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

就一个剪枝。157MS。应该是数据太弱

Posted by xiaosiwei at 2009-11-22 15:27:01 on Problem 2531
#include <stdio.h>
#include <string.h>

int used[22],c[22][22],n,max,k;

void DFS(int l,int cnt,int sum)
{
	if(cnt > k)
		return;
	if(l > n)
		return;

	used[l] = 1;
	int sum1;
	sum1 = sum;
	for(int i = 1;i <= n;i++)
	{
		if(!used[i])
			sum1 += c[i][l];
		else
			sum1 -= c[i][l];
	}
	if(sum1 > max)
		max = sum1;
	DFS(l+1,cnt+1,sum1);

	used[l] = 0;
	DFS(l+1,cnt,sum);	
}

int main()
{
	while(scanf("%d",&n) != EOF)
	{
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++)
				scanf("%d",&c[i][j]);

		max = 0;
		memset(used,0,sizeof(used));
		k = n >> 1;
		DFS(1,1,0);
		printf("%d\n",max);
	}
	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