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 |
dp入门#include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int maxroad[101][101]; int d[101][101]; int n; int MAXroad(int i,int j) { if (maxroad[i][j]!= -1) { return maxroad[i][j]; } if (i == n) { maxroad[i][j]=d[i][j]; } else { int x = MAXroad(i + 1, j); int y = MAXroad(i + 1, j + 1); maxroad[i][j] = max(x, y) + d[i][j]; } return maxroad[i][j]; } int main() { int i, j; cin >> n; for(i=1;i<=n;i++) for (j = 1; j <=i; j++) { cin >> d[i][j]; } memset(maxroad, -1, sizeof(maxroad)); cout << MAXroad(1,1) << endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator