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

Re:觉得应该可以,可以过Sample,但WA了,请教有什么没考虑好的,谢谢

Posted by PC0400322032 at 2004-08-13 17:21:23 on Problem 1348
In Reply To:不知道可不可以简化成这样搜 Posted by:PC0400322032 at 2004-08-13 17:19:59
> #include <stdio.h>
> int v[5],a[6];
> bool dfs(int k,int m)
> {
> 	if(k==4)
> 	{
> 		if(m==a[4])
> 			return 1;
> 		else
> 			return 0;
> 	}
> 	for(int i=0;i<4;i++)
> 		if(v[i]==0)
> 		{
> 			v[i] = 1;
> 			if(dfs(k+1,m*a[i]))
> 				return 1;
> 			if(dfs(k+1,m+a[i]))
> 				return 1;
> 			if(dfs(k+1,m-a[i]))
> 				return 1;
> 			if(a[i]!=0)
> 			{
> 				if(dfs(k+1,m/a[i]))
> 					return 1;
> 			}
> 			v[i] = 0;
> 		}
> 	return 0;
> }
> bool done()
> {
> 	for(int i=0;i<4;i++)
> 	{
> 		v[i] = 1;
> 		if(dfs(1,a[i]))
> 			return 1;
> 	}
> 	return 0;
> }
> void main()
> {
> 	int i;
> 	while(1)
> 	{
> 		scanf("%d",&a[0]);
> 			if(a[0]<0)
> 				break;
> 		v[0] = 0;
> 		for(i=1;i<5;i++)
> 		{
> 			scanf("%d",&a[i]);
> 			v[i] = 0;
> 		}
> 		for(i=0;i<5;i++)
> 			printf("%d ",a[i]);
> 		if(done())
> 			printf("OK!\n");
> 		else
> 			printf("NO!\n");
> 	}
> }

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