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

汗死,原来卡了一个常数。。。把一个valid函数去掉反而没有问题了。其实这个本来就没有必要。

Posted by yogafrank at 2008-10-15 18:54:29 on Problem 2531
In Reply To:偶暴力就没有过。。。TLE了,但是看了你的居然过了。好奇怪。 Posted by:yogafrank at 2008-10-15 18:50:51
> #include <iostream>
> using namespace std;
> 
> bool used[20];
> int matrix[20][20];
> int n, result;

> 
> int caculate ()
> {
> 	int sum = 0;
> 	for ( int i = 0; i < n; i++ )
> 	{
> 		if ( used[i] )
> 		{
> 			for ( int j = 0; j < n; j++ )
> 				if ( !used[j] )
> 					sum += matrix[i][j];
> 		}
> 	}
> 
> 	return sum;
> }
> 
> void search ( int index )
> {
> 	if ( index == n )
> 	{
> 		result = result > caculate () ? result : caculate ();
> 		return;
> 	}
> 
> 	used[index] = true;
> 	search ( index + 1 );
> 	used[index] = false;
> 	search ( index + 1 );
> }
> 
> int main()
> {
> 	int i, j;
> 	scanf ( "%d", &n );
> 	for ( i = 0; i < n; i++ )
> 		for ( j = 0; j < n; j++ )
> 			scanf ( "%d", &matrix[i][j] );
> 	result = -1;
> 	search ( 0 );
> 	printf ( "%d\n", result ); 
> 	return 0;
> }
> 


However, I was so close to death. For the execution time of this code is 1625MS.....ORZ...

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