#include<iostream> #include<algorithm> using namespace std; int main() { int n, m, i, j, Max; int dp[100][100], a[100][100]; scanf("%d", &n); while (n--) { scanf("%d", &m); for (i = 0; i < m; i++) for (j = 0; j <= i; j++) scanf("%d", &a[i][j]); dp[0][0] = a[0][0]; Max = 0; for(i = 1; i < m; i++) for (j = 0; j <= i; j++) { if (j == 0) dp[i][j] = dp[i - 1][j] + a[i][j]; else if (i == j) dp[i][j] = dp[i - 1][j - 1] + a[i][j]; else dp[i][j] = max((dp[i - 1][j - 1] + a[i][j]), (dp[i - 1][j] + a[i][j])); Max = max(dp[i][j], Max); } printf("%d\n", Max); } return 0; }
0.0分
0 人评分
printf基础练习2 (C语言代码)浏览:826 |
1908题解浏览:680 |
1126题解浏览:649 |
简单的a+b (C语言代码)浏览:618 |
简单的a+b (C语言代码)浏览:683 |
最好的,浏览:601 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:529 |
筛排处理 (C语言代码)浏览:830 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1288 |
C语言程序设计教程(第三版)课后习题7.2 (C++代码)浏览:452 |