标签:
5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
30
测试代码
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int n, i, j; 7 int **tra; 8 scanf("%d", &n); 9 //创建二维动态数组 10 tra = new int*[n]; 11 for (i = 0; i < n; i++) 12 { 13 tra[i] = new int[i + 1]; 14 for (j = 0; j <= i; j++) 15 { 16 scanf("%d", &tra[i][j]); 17 } 18 } 19 for (i = n - 1; i >= 0; i--) 20 { 21 for (j = 0; j < i; j++) 22 { 23 if (tra[i][j] > tra[i][j + 1]) 24 { 25 tra[i - 1][j] += tra[i][j]; 26 } 27 else 28 { 29 tra[i - 1][j] += tra[i][j + 1]; 30 } 31 } 32 } 33 printf("%d\n", tra[0][0]); 34 for (i = 0; i < n; i++) 35 { 36 delete[] tra[i]; 37 } 38 delete []tra; 39 return 0; 40 }
标签:
原文地址:http://www.cnblogs.com/maxin/p/5478831.html