POJ 1014
#include<iostream>
#include<stdio.h>
#define num 6
using namespace std;
bool DFS(int i,int half_sum);
int a[num];
int half_value;
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int sum;
int time = 0;
while(1)
{
sum = 0;
for(i = 0; i < num; ++ i)
{
cin>>a[i];
}
if(!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
break;
for(i = 0; i < num; ++ i)
{
a[i] %= 30;
sum += a[i]*(i+1);
}
cout<<"Collection #";
cout<<++ time<<":"<<endl;
if(sum % 2 != 0)
{
cout<<"Can't be divided."<<endl;
cout<<endl;
continue;
}
half_value = sum / 2;
if(DFS(0,0))
cout<<"Can be divided."<<endl;
else
cout<<"Can't be divided."<<endl;
cout<<endl;
}
}
bool DFS(int i,int half_sum)
{
int j;
if(i == 6)
return false;
for(j = 0; j <= a[i]; ++ j)
{
if(j != 0)
half_sum += (i+1);
else
half_sum += 0;
if(half_sum == half_value)
return true;
else if(half_sum > half_value)
return false;
if(DFS(i+1,half_sum))
return true;
}
return false;
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com