标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 32468 Accepted Submission(s): 19417
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 const int N = 105; 6 int mp[N][N]; 7 int dp[N][N]; 8 int main() 9 { 10 int t; 11 scanf("%d",&t); 12 while(t--) 13 { 14 memset(dp,0,sizeof(dp)); 15 int n; 16 scanf("%d",&n); 17 for(int i = 0; i < n; i++) 18 for(int j = 0; j <= i; j++) 19 scanf("%d",&mp[i][j]); 20 for(int i = 0; i < n; i++) dp[n-1][i] = mp[n-1][i]; 21 for(int i = n-2; i >= 0; i--) 22 for(int j = 0; j <= i; j++) 23 dp[i][j] = max((mp[i][j]+dp[i+1][j]),(mp[i][j]+dp[i+1][j+1])); 24 printf("%d\n",dp[0][0]); 25 } 26 return 0; 27 }
标签:
原文地址:http://www.cnblogs.com/shanyr/p/5228588.html