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 |
1A代码#include <iostream> using namespace std; int cows[351][351]; int dp[351][351]; int max(int i,int j) { if(i>=j) return i; else return j; } int main() { int rows; cin>>rows; for(int i=1;i<=rows;i++) { for(int j=1;j<=i;j++) cin>>cows[i][j]; } for(int i=1;i<=rows;i++) { for(int j=1;j<=i;j++) { dp[i][j]=max(dp[i-1][j]+cows[i][j],dp[i-1][j-1]+cows[i][j]); } } int maxnum=0; for(int i=1;i<=rows;i++) { if(dp[rows][i]>maxnum) maxnum=dp[rows][i]; } cout<<maxnum<<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