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

Posted by 1423302 at 2015-03-13 20:02:59 on Problem 2362
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int len[30]; int num; bool used[30];
bool dfs(int l, int need, int res)
{
	//printf("dfs%d %d %d\n", l, need, res);
	//bool tmp[10003]; memset(tmp, 1, sizeof(tmp));
	if (res == 0 && need == 0)return true;
	if (res == 0 && need != 0)return false;
	if (need == 0)need = l;
	for (int i = num-1; i >-1; i--)
	{
		if (len[i] <= need&&used[i] == 0)// && tmp[len[i]] == 1)
		{
			used[i] = 1;
			if (dfs(l, need - len[i], res - 1))return true;
			used[i] = 0; //tmp[len[i]] = 0;
			if (need == l)return false;
		}
	}
}
int main()
{
	int test; cin >> test;
	while (test != 0)
	{
		int sum = 0; int big = 0;
		test--;
		memset(len, 0, sizeof(len)); memset(used, 0, sizeof(used));
		cin >> num;
		for (int i = 0; i < num; i++)
		{
			cin >> len[i]; sum += len[i];big = max(big,len[i]);
		}
		if (sum % 4 != 0){ cout << "no" << endl; continue; }
		int l = sum / 4;
		if (l<big){ cout << "no" << endl; continue; }
		sort(len, len + num);
		if (dfs(l, l, num)){ cout << "yes" << endl; continue; }
		cout << "no" << endl; continue;
	}
	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