标签:oid cin step clu include sam ret contain follow
Description
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
(Figure 1)
Input
Output
Sample Input
5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
Sample Output
30
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main(void) { int num[110][110], dp[110][110]; int n; memset(dp, -1, sizeof(dp)); cin >> n; for(int i = 0; i < n; i++) { for(int j = 0; j <= i; j++) { scanf("%d", &num[i][j]); if(i == n-1) dp[i][j] = num[i][j]; } } for(int i = n-2; i >= 0; i--) { for(int j = 0; j <= i; j++) { dp[i][j] = max(dp[i+1][j]+num[i][j], dp[i+1][j+1]+num[i][j]); } } cout << dp[0][0] << endl; return 0; }
标签:oid cin step clu include sam ret contain follow
原文地址:http://www.cnblogs.com/limyel/p/7198641.html