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<iostream> using namespace std; #define MAX 100 int tri[MAX][2*MAX]; int main() { int n; cin>>n; int i,j,first,last; for(i=0,first=n-1,last=n-1;i!=n;++i,--first,++last) for(j=first;j<=last;j+=2) cin>>tri[i][j]; for(i=n-2,first=1,last=2*n-3;i>=0;--i,++first,--last) { int k=i+1; for(j=first;j<=last;j+=2) { int max; max=(tri[k][j-1]>tri[k][j+1])?tri[k][j-1]:tri[k][j+1]; tri[i][j]+=max; } } cout<<tri[0][n-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