Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

回溯能不超时吗

Posted by nyl310809010320 at 2011-04-05 22:10:26 on Problem 1163
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator