标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 42547 | Accepted: 25721 |
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"cstdio" #include"cstring" #include"algorithm" using namespace std; const int MAXN=1005; const int INF=0x3fffffff; int n; int a[MAXN][MAXN]; int dp[MAXN][MAXN]; int main() { scanf("%d",&n); for(int i=0;i<n;i++) for(int j=0;j<=i;j++) scanf("%d",&a[i][j]); for(int i=n-1;i>=0;i--) for(int j=0;j<=i;j++) dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+a[i][j]; printf("%d\n",dp[0][0]); return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5185669.html