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 cangratul at 2009-05-24 17:21:44 on Problem 1564 and last updated at 2009-05-24 17:26:15
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<fstream>
#include<map>
#include<list>
#include<sstream>
#include<queue>
#include<set>
using namespace std;
set<vector<int> > hash;
int a[12];
int main()
{
	int t,n;
	while(scanf("%d %d",&t,&n)&&t)
	{
		hash.clear();
		for(int i=0;i<n;i++) scanf("%d",a+i);
		printf("Sums of %d:\n",t);
		char ok=0;
		for(int i=(1<<n)-1;i>=0;i--)
		{
			int tmp=0,mask=1<<n;
			vector<int> tp1;
			for(int j=0;j<n;j++)
			{
				mask>>=1;
				if(mask&i) {tmp+=a[j]; tp1.push_back(a[j]);}
			}
			if(tmp==t&&hash.find(tp1)==hash.end())
			{
				hash.insert(tp1);
				ok=1;
				for(int j=0;j<tp1.size();j++)
				{
					printf("%d",tp1[j]);
					if(j==tp1.size()-1) putchar('\n');
					else putchar('+');
				}
			}
		}
		if(!ok) puts("NONE");
	}
}

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