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> using namespace std; int a[101][101]; int highsum = 0; int tempsum = 0; int N; void sum(int highsum,int i,int j) { if(i>N&& highsum > tempsum ) { tempsum = highsum;return; } highsum += a[i][j]; if( highsum+(N-i)*99>tempsum) sum(highsum,i + 1,j); if( highsum+(N-i)*99>tempsum) sum(highsum,i + 1,j + 1); } int main() { cin >> N; for( int i = 1 ;i <= N; ++i) for(int j = 1; j <= i ;++j) cin >> a[i][j]; sum(highsum,1,1); cout<<tempsum; //system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator