| ||||||||||
| 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了的程序运行了半天也没个结果~~我以前WA的程序是秒杀的……In Reply To:一组比较BT的数据! Posted by:winboycool at 2007-04-22 00:07:27 #include<iostream>
#include<algorithm>
using namespace std;
int s[65];
int n;
int x;
bool bfs(int sum,int m)
{
if(sum==0)
{
m--;
if(m==0)return true;
else if(bfs(x,m)==false)return false;
else return true;
}
else if(sum==x)
{
int i=n;
do{i--;}while(s[i]<0);
s[i]=-s[i];
if(bfs(sum+s[i],m)==false){s[i]=-s[i];return false;}
return true;
}
else
{
int i=n;
goto check;
check:do{i--;}while((i>=0)&&(s[i]<0||s[i]>sum||s[i]==s[i+1]));
if(i>=0)
{ s[i]=-s[i];
if(bfs(sum+s[i],m)==false){s[i]=-s[i];goto check;}
return true;
}
else return false;
}
}
int main()
{
while(cin>>n&&n)
{
int sum=0;
for(int i=0;i<n;i++){cin>>s[i];sum+=s[i];}
sort(s,s+n);
for(int i=n;i>0;i--)if(sum%i==0){x=sum/i;if(bfs(x,i)){cout<<x<<endl;break;}for(int i=0;i<n;i++)s[i]=abs(s[i]);}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator