//https://algospot.com/judge/problem/read/TRIANGLEPATH |
#include <iostream> |
using namespace std; |
int dp[101][101]; |
int tri[101][101]; |
int main() |
{ |
int c; |
cin >> c; |
for(int t=0; t<c; t++) |
{ |
int n; |
cin >> n; |
for(int i=1; i<=n; i++) |
for(int j=1; j<=i; j++) |
cin >> tri[i][j]; |
dp[1][1]=tri[1][1]; |
for(int i=1; i<=n; i++) |
{ |
dp[i][1]=tri[i][1]+dp[i-1][1]; |
for(int j=2; j <i ; j++) |
{ |
if(dp[i-1][j]>dp[i-1][j-1]) |
dp[i][j]=tri[i][j]+dp[i-1][j]; |
else |
dp[i][j]=tri[i][j]+dp[i-1][j-1]; |
} |
dp[i][i]=tri[i][i]+dp[i-1][i-1]; |
} |
int max1=0; |
for(int i=1; i<=n; i++) |
if(max1<dp[n][i]) max1=dp[n][i]; |
cout << max1 << endl; |
} |
} |
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
180105_10707_수도요금 (0) | 2018.01.05 |
---|---|
180104_13116_30번 (0) | 2018.01.04 |
180102_2884_알람 시계 (0) | 2018.01.02 |
180101_11047_동전0 (0) | 2018.01.01 |
171230_2217_로프 (0) | 2017.12.30 |