标签:class 背包 sum == ber 3.1 ural stream exp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 26842 Accepted Submission(s): 7687
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; int a[9]; int dp[100009]; int main() { int cast=0; while(scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])) { if(a[1]==0 && a[2]==0 && a[3]==0 && a[4]==0 && a[5]==0 && a[6]==0) break; printf("Collection #%d:\n",++cast); int sum=a[1]*1+a[2]*2+a[3]*3+a[4]*4+a[5]*5+a[6]*6; memset(dp,62,sizeof(dp)); dp[0]=0; if(sum&1) printf("Can‘t be divided.\n\n"); else { sum/=2; for(int i=1;i<=6;i++) { for(int k=1;a[i];k*=2) { if(a[i]<k) k=a[i]; for(int j=sum;j>=k*i;j--) { dp[j]=min(dp[j],dp[j-k*i]+k*i); } a[i]-=k; } } if(dp[sum]==sum) printf("Can be divided.\n\n"); else printf("Can‘t be divided.\n\n"); } } return 0; }
标签:class 背包 sum == ber 3.1 ural stream exp
原文地址:http://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7298393.html