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 |
暴力搜索没错!0ms就是这样诞生的。(附保证不ac的代码)In Reply To:有没搞错,这什么DP.....还是暴力有效 Posted by:cx19860824 at 2007-03-27 10:19:42 int weights[10],N,P,res[10],used[11]; int f(int id,int now) { if (id==N && now==0)return 1; if ((id==N && now!=0) || now<0)return 0; for (int i=1;i<=N;i++)if (used[i]==0){ used[res[id]=i]=1; if (f(id+1,now-i*weights[id]))return 1; used[i]=0; } return 0; } int main() { scanf("%d %d",&N,&P); for (int i=0;i<N;i++){ weights[i]=1; for (int j=i-1;j>0;j--)weights[j]+=weights[j-1]; } memset(used,0,sizeof(used)); f(0,P); for (int i=0;i<N;i++)printf((i==N-1)?"%d\n":"%d ",res[i]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator