| ||||||||||
| 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 | |||||||||
大牛好,大牛您的剪枝不够强!In Reply To:help!!why tle?? Posted by:shenfangyi at 2007-01-20 20:07:08 > #include<stdio.h>
> #include<string.h>
> #include<algorithm>
> using namespace std;
> int a[70],s[70],m,t,n;
> bool dfs(int x,int y,int max)
> {
> if(x<0)return true;
> int i=0;
> if(x<n-1&&s[x]==s[x+1])i=y-1;
> for(;i<=max&&i<t/m;i++)if(a[i]+s[x]<=m)
> {
> a[i]+=s[x];
> if(dfs(x-1,i+1,(i+1>max)?i+1:max))return true;
> a[i]-=s[x];
> }
> return false;
> }
> int main()
> {
> scanf("%d",&n);
> while(n)
> {
> t=0;
> for(int i=0;i<n;i++)scanf("%d",s+i),t+=s[i];
> sort(s,s+n);
> for(m=s[n-1];m<t;m++)if(t%m==0)
> {
> memset(a,0,sizeof(a));
> if(dfs(n-1,0,0))break;
> }
> printf("%d\n",m);
> scanf("%d",&n);
> }
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator