北大ACM(POJ1014-Dividing)

Question:http://poj.org/problem?id=1014
问题点:抽屉原理、dfs、多重背包。
 Memory: 248K        Time: 16MS
Language: C++ Result: Accepted #include <iostream>
using namespace std;
int arr_i[];
bool dfs(int v,int c)
{
if(v==) return true;
if(c==||v<) return false;
for(int i=;i<=arr_i[c-];i++)
{
if(dfs(v-c*i,c-)) return true;
}
return false;
}
int main()
{
int cnt=;
while(true)
{
int sum,half,i,j,k,n,v;
cnt++;
for(i=,sum=,half=;i<;i++)
{
cin>>arr_i[i];
sum+=arr_i[i]*(i+);
switch(i)
{
case :if(arr_i[i]>) arr_i[i]=+arr_i[i]%;break;
case :if(arr_i[i]>) arr_i[i]=+arr_i[i]%;break;
case :if(arr_i[i]>) arr_i[i]=+arr_i[i]%;break;
case :if(arr_i[i]>) arr_i[i]=+arr_i[i]%;break;
case :if(arr_i[i]>) arr_i[i]=+arr_i[i]%;break;
case :if(arr_i[i]>) arr_i[i]=+arr_i[i]%;break;
}
half+=arr_i[i]*(i+);
}
if(sum==) break;
cout<<"Collection #"<<cnt<<":"<<endl;
if(sum%==){
cout<<"Can't be divided."<<endl<<endl;
continue;
}
half/=;
if(dfs(half,)) cout<<"Can be divided."<<endl<<endl;
else cout<<"Can't be divided."<<endl<<endl;
}
return ;
}
 
上一篇:Java NIO之缓冲区Buffer


下一篇:NOIP2017游记