Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
AC (/≧▽≦)/感觉这题并不难呀#include <iostream> #include <stdio.h> #include <iomanip> #include <math.h> #include <string.h> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #define inf 99999999 typedef long long ll; typedef unsigned long long ull; using namespace std; int tar,l,maxs=0; map<int,int> mp; vector<int> vec,tvec; string num; void dfs(int ans,int n)//在第n位之前切割 { if(n==l) { if(ans<=tar&&ans>=maxs) { mp[ans]++; tvec=vec; maxs=max(maxs,ans); } return ; } for(int i=n+1;i<=l;i++)//选择下一个切割位置:i { int res=0; for(int j=i-1,k=0;j>=n;j--,k++) res+=pow(10,k)*(num[j]-'0'); vec.push_back(res); dfs(ans+res,i); vec.pop_back(); } } int main() { while(cin>>tar>>num) { if(tar==0&&num=="0")return 0; mp.clear(); vec.clear(); maxs=0; l=num.length(); dfs(0,0); if(maxs==0)cout<<"error"; else if(mp[maxs]>1)cout<<"rejected"; else { cout<<maxs; for(int i=0;i<tvec.size();i++) cout<<" "<<tvec[i]; } cout<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator