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

这个程序在JOJ上过了,可是POJ上却wa……谁能找到使这个程序wa的测试数据……

Posted by goodness at 2009-10-23 21:02:12 on Problem 1564
#include <iostream>
#include <cstdio>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

long in[20],ans[20],flag[20],mark;
string get,tmp;
set<string> out;

string change(long num){
	string ret="",tmp="";
	tmp+=num%10+'0';
	while(num/=10) tmp+=num+'0';
	for(long i=tmp.size()-1;i>=0;i--) ret+=tmp[i];
	return ret;
}

void dfs(long s,long top,long n){
	long i,j;
	for(i=top-1;i>=0;i--){
		if(in[i]==s){
			get=""; ans[n]=s;
			for(j=0;j<n;j++) get+=change(ans[j])+"+";
			get+=change(ans[n]);
			if(out.insert(get).second) printf("%s\n",get.c_str());
			mark=1;
		}else if(in[i]<s){
			ans[n]=in[i];
			dfs(s-in[i],i,n+1);
		}
	}
}

int main()
{
	long t,n,i,ansNum;
	while(scanf("%ld%ld",&t,&n),n){
		mark=0; out.clear();
		for(i=0;i<n;i++) scanf("%ld",&in[i]);
		sort(in,in+n);
		printf("Sums of %ld:\n",t);
		dfs(t,n,0);
		if(!mark) printf("NONE\n");
	}
	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