解题思路:
注意事项:
参考代码:
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <functional> #include <iostream> #include <algorithm> using namespace std; const int maxn = 101; const int INF = -2100000000; int a[maxn][maxn], n, d[maxn][maxn]; int dp(int i, int j) { if(d[i][j] >= 0) { return d[i][j]; } else { return d[i][j] = a[i][j] + (i == n ? 0 : max(dp(i+1,j),dp(i+1,j+1))); } } int main() { memset(d,-1,sizeof(d)); scanf("%d", &n); for(int i = 1; i <= n; ++i) { for(int j = 1; j <= i; ++j) { scanf("%d", &a[i][j]); } } printf("%d\n", dp(1,1)); return 0; }
0.0分
2 人评分
简单的a+b (C语言代码)浏览:1108 |
C语言程序设计教程(第三版)课后习题6.7 (C++代码)(经常这样写会不会被打死)浏览:2510 |
C语言训练-求矩阵的两对角线上的元素之和 (C++代码)浏览:805 |
十->二进制转换 (C++代码)(零和负数需要特殊处理)浏览:1040 |
简洁的代码浏览:1409 |
点我有惊喜!你懂得!浏览:2072 |
简单的a+b (C语言代码)浏览:548 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:1095 |
【计算直线的交点数】 (C语言代码)浏览:1450 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:531 |