标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 32087 Accepted Submission(s): 19162
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 const int maxn=105; 7 int a[maxn][maxn]; 8 int d[maxn][maxn]; 9 10 int main() 11 { 12 int t,n; 13 scanf("%d",&t); 14 while(t--) 15 { 16 scanf("%d",&n); 17 for(int i=1;i<n;i++) 18 for(int j=1;j<n;j++) 19 d[i][j]=0; 20 for(int i=1;i<=n;i++) 21 for(int j=1;j<=i;j++) 22 scanf("%d",&a[i][j]); 23 for(int i=1;i<=n;i++) d[n][i]=a[n][i]; 24 for(int i=n-1;i>=1;i--) 25 for(int j=1;j<=i;j++) 26 d[i][j]=a[i][j]+max(d[i+1][j],d[i+1][j+1]); 27 printf("%d\n",d[1][1]); 28 } 29 }
标签:
原文地址:http://www.cnblogs.com/cumulonimbus/p/5185086.html