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 Spacesheep at 2005-08-19 20:03:12 on Problem 2531
In Reply To:up,过了的同志随便说一说 Posted by:bakey at 2005-08-19 19:34:50
#include<stdio.h>
#define maxn 30


int i,j,n,m,ans,now;

bool q[maxn];

int p[maxn][maxn];

void search(int a){
		if (a>n){
		if (now>ans) ans=now;
		return;
	};
	int i,dome=now;
	q[a]=0;
	for (i=1;i<a;i++) if (q[i]) now+=p[a][i];
	search(a+1);
	now=dome;
	q[a]=1;
	for (i=1;i<a;i++) if (!q[i])now+=p[a][i];
	search(a+1);
	return;
};
	
	




int main(){

	scanf("%d",&n);
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++) 
			scanf("%d",&p[i][j]);
	search(1);
	printf("%d",ans);
	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