Nyoj 456

来源:互联网 发布:帝国cms灵动标签大全 编辑:程序博客网 时间:2024/05/22 03:24
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int MAXN = 12;int num[MAXN];int totalvalue;bool DFS(int sum){    if(sum == totalvalue)        return true;    for(int i = 10; i >= 1; --i)    {        if(num[i] > 0 && sum + i <= totalvalue)        {            num[i]--;            return DFS(sum+i);        }    }    return false;}int main(){    int kcase = 1;    while(1)    {        totalvalue = 0;        memset(num, 0, sizeof(num));        for(int i = 1; i <= 10; ++i)        {            cin>>num[i];            totalvalue += num[i]*i;        }        if(!totalvalue)            break;        if(totalvalue & 1)        {            cout<<"#"<<kcase++<<":Can't be divided."<<endl<<endl;            continue ;        }        totalvalue >>= 1;        if(DFS(0))            cout<<"#"<<kcase++<<":Can be divided."<<endl<<endl;        else            cout<<"#"<<kcase++<<":Can't be divided."<<endl<<endl;    }    return 0;}

0 0
原创粉丝点击