| ||||||||||
| 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 | |||||||||
求大神看一看啊,为什么会错,能找到的数据算出来都没问题啊
#include <iostream>
using namespace std;
int marbles[6];
bool dfs(int now,int goal)
{
for(int i=0;i<6;i++)
{
if(now+i+1==goal && marbles[i]>0)
{
marbles[i]--;
return true;
}
if(now+i+1<goal && marbles[i]>0)
{
marbles[i]--;
if(dfs(now+i+1,goal)) return true;
marbles[i]++;
// if(i==0) return false;
continue;
}
if(now+i+1>goal && marbles[i]>0) return false;
}
}
int main()
{
int all_count=1;//用于记录总共的次数
while(true)
{
int zero_count=0;//用于记录一组数据中0出现的次数
int value_sum=0;//用于记录总价值
for(int i=0;i<6;i++) {
cin >> marbles[i];
if(marbles[i]==0) zero_count++;
if(marbles[i]>6)
{
if(marbles[i]%2)
marbles[i]=5;
else marbles[i]=6;
}
value_sum+=(i+1)*marbles[i];
}
if(zero_count==6) {
// cout<<endl;
return 0;
}
zero_count=0;
if(value_sum%2!=0)
{
cout<<"Collection #"<<all_count<<":"<<endl;
cout<<"Can't be divided."<<endl;
}
else{
if(dfs(0,value_sum/2))
{
cout<<"Collection #"<<all_count<<":"<<endl;
cout<<"Can be divided."<<endl;
}
else
{
cout<<"Collection #"<<all_count<<":"<<endl;
cout<<"Can't be divided."<<endl;
}
}
all_count++;
cout<<endl;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator