Description
Input
Output
Sample Input
1 5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
Sample Output
30
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; int cmp(int a,int b) { return a>b; } int main() { int n; scanf("%d",&n); while(n--) { int a[107][107],b[107][107]; int m,i,j,k; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d",&m); for(i=1;i<=m;i++) { for(j=1;j<=i;j++) { scanf("%d",&a[i][j]); } } for(i=1;i<=m;i++) { for(j=1;j<=i;j++) { if(a[i-1][j]>a[i-1][j-1]) { a[i][j]+=a[i-1][j]; } else { a[i][j]+=a[i-1][j-1]; } } } sort(a[m],a[m]+107,cmp); printf("%d\n",a[m][0]); } return 0; }
原文地址:http://blog.csdn.net/floating_life/article/details/43267219