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 |
为什么我的代码wa掉了???#include<iostream> //#include<vector> #include<algorithm> using namespace std; int tri[500][500]; const int down_left=0,down_right=1,up_left=-1,up_right=0; int i=1; void solve_pro( ) { int k; int sum=0; for(int j=0;j!=i-1;j++) { sum; int b; int a = tri[i-2][j]; b = max(tri[i-1][j+down_left],tri[i-1][j+down_right]); // cout<<a<<" "<<b<<endl; if( sum < a+b ) { sum = a+b; // h = i-1; k = j; // cout<<sum<<endl; } } i=i-2; while( i-- ) { if( k >= 0 ) { sum += max(tri[i][k+up_left],tri[i][k+up_right]); if(tri[i][k+up_left] >= tri[i][k+up_right]) k = k + up_left; else k = k + up_right; } else sum +=tri[i][k+up_right]; } cout<<sum<<endl; } int main() { int num; cin>>num; while( num-- ) { for(int j=0;j!=i;j++) { cin>>tri[i][j]; } i++; } solve_pro(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator