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

哪位大牛能告诉小弟为什么我的总是WA?数据8 1 2 3 4 4 6 6 6也过了,就不知道为什么总是WA

Posted by await8157 at 2013-02-04 15:52:10 on Problem 2362 and last updated at 2013-02-05 15:56:14
#include <iostream>
#include <algorithm>
using namespace std;
int m,sum,t,True,n;
int M[22];
bool vis[22];
void dfs(int num,int lenth,int cs);//num为起点,lenth为前num个数的和(可能加/不加)
inline bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
	cin>>n;
	while(n--)
	{ 
		sum=0;
		memset(M,0,sizeof(M));
		memset(vis,false,sizeof(vis));
		cin>>m;
		for(int i=0;i<m;i++)
		{ 
			cin>>M[i];
			sum+=M[i];
		}
		sort(M,M+m,cmp);//降序
		int maxn=M[0];
		if(sum%4!=0||4*maxn>sum)
		{ 
			cout<<"no"<<endl;
			continue;
		}
		t=sum/4;
		dfs(0,0,0);
		if(True) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	system("pause");
	return 0;
}

void dfs(int num,int lenth,int cs)
{
	if(cs==3) { True=1;return ;}
	if(lenth==t) dfs(0,0,cs+1);
	if(True) return ;
	for(int i=num;i<m;i++)
	{
		if(!vis[i]&&M[i]+lenth<=t)
		{
			vis[i]=true;
			dfs(i+1,lenth+M[i],cs);
			if(True) return ;
			vis[i]=false;
		}
	}
}
知道原因了····
大家注意数据组之间要清理

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