Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
自底向上#include <iostream> #include <cstdio> using namespace std; const int M = 1005; int i,j,k; int Max(int x ,int y) { return x>y?x:y; } int a[105][105]; int m[105][105]; int main () { int n; while (scanf ("%d",&n)!=EOF) { for (i=1;i<=n;i++) { for (j=1;j<=i;j++) { cin >> a[i][j]; } } for (i=n;i>=1;i--) { for (j=1;j<=i;j++) { m[i][j] = Max(m[i+1][j],m[i+1][j+1]) + a[i][j]; //自底向上选择DP方向。 } } cout <<m[1][1] <<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator