poj 1014 Dividing

题目链接:http://poj.org/problem?id=1014

解题思路:简单dp

 1 ///////////////////////////////////////////////////////////////////////////
 2 //problem_id: poj 1014
 3 //user_id: SCNU20102200088
 4 ///////////////////////////////////////////////////////////////////////////
 5 
 6 #include <algorithm>
 7 #include <iostream>
 8 #include <iterator>
 9 #include <iomanip>
10 #include <cstring>
11 #include <cstdlib>
12 #include <string>
13 #include <vector>
14 #include <cstdio>
15 #include <cctype>
16 #include <cmath>
17 #include <queue>
18 #include <stack>
19 #include <list>
20 #include <set>
21 #include <map>
22 using namespace std;
23 
24 ///////////////////////////////////////////////////////////////////////////
25 typedef long long LL;
26 const double PI=acos(-1.0);
27 
28 const int x4[]={-1,0,1,0};
29 const int y4[]={0,1,0,-1};
30 const int x8[]={-1,-1,0,1,1,1,0,-1};
31 const int y8[]={0,1,1,1,0,-1,-1,-1};
32 
33 typedef int T;
34 T max(T a,T b){ return a>b? a:b; }
35 T min(T a,T b){ return a<b? a:b; }
36 ///////////////////////////////////////////////////////////////////////////
37 
38 ///////////////////////////////////////////////////////////////////////////
39 //Add Code:
40 ///////////////////////////////////////////////////////////////////////////
41 
42 int main(){
43     ///////////////////////////////////////////////////////////////////////
44     //Add code:
45     int i,j,k,Case=1,n[10];
46     while(scanf("%d",&n[1])!=EOF){
47         int sum=n[1];
48         for(i=2;i<=6;i++){
49             scanf("%d",&n[i]);
50             sum+=n[i]*i;
51         }
52         if(sum==0) break;
53         if(Case>1) printf("\n");
54         printf("Collection #%d:\n",Case++);
55         if(sum&1) printf("Can't be divided.\n");
56         else{
57             int num=sum/2;
58             bool flag[60005]={0};
59             flag[0]=1;
60             for(i=1;i<=6;i++){
61                 int cnt[60005]={0};
62                 for(j=0;j<=num-i;j++){
63                     if(flag[j] && cnt[j]<n[i] && !flag[j+i]){
64                         flag[j+i]=1;
65                         cnt[j+i]=cnt[j]+1;
66                         if(j+i==num) goto out;
67                     }
68                 }
69             }
70             out:;
71             if(flag[num]) printf("Can be divided.\n");
72             else printf("Can't be divided.\n");
73         }
74     }
75     ///////////////////////////////////////////////////////////////////////
76     return 0;
77 }
78 
79 ///////////////////////////////////////////////////////////////////////////
80 /*
81 Testcase:
82 Input:
83 1 0 1 2 0 0
84 1 0 0 0 1 1
85 0 0 0 0 0 0
86 Output:
87 Collection #1:
88 Can't be divided.
89 
90 Collection #2:
91 Can be divided.
92 */
93 ///////////////////////////////////////////////////////////////////////////

posted on 2013-08-24 10:43  SCNU20102200088  阅读(164)  评论(0编辑  收藏  举报

导航