标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 34230 Accepted Submission(s): 20423
1 #include <iostream> 2 using namespace std; 3 int reward[100][100], best[100][100]; 4 int main() { 5 int test, n; 6 cin >> test; 7 8 while(test--){ 9 cin >> n; 10 11 for(int i = 0; i < n; i++) 12 for(int j = 0; j <= i; j++) 13 cin >> reward[i][j]; 14 15 best[0][0] = reward[0][0]; 16 17 for (int i = 1; i < n; i++){ 18 for (int j = 0; j <= i; j++) { 19 if(j == 0) 20 best[i][j] = best[i-1][j] + reward[i][j]; 21 else if (i == j) 22 best[i][j] = best[i-1][j-1] + reward[i][j]; 23 else 24 best[i][j] = (best[i-1][j] > best[i-1][j-1] ? best[i-1][j] : best[i-1][j-1]) + reward[i][j]; 25 } 26 } 27 28 int max = best[n-1][0]; 29 for(int i = 1; i < n; i++){ 30 if(best[n-1][i] > max) 31 max = best[n-1][i]; 32 } 33 34 cout << max << endl; 35 } 36 //system("pause"); 37 return 0; 38 }
标签:
原文地址:http://www.cnblogs.com/qinduanyinghua/p/5483266.html