标签:des style blog http color os strong io
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
1 0 1 2 0 0 1 0 0 0 1 1 0 0 0 0 0 0
Sample Output
Collection #1: Can‘t be divided. Collection #2: Can be divided.
解题:多重背包的二进制优化,第一次搞二进制优化啊。。。。。。无尽的WA
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #define LL long long 13 #define INF 0x3f3f3f3f 14 using namespace std; 15 int dp[200000],w[8] = {0,1,2,3,4,5,6}; 16 int num[7],sum,val; 17 int main() { 18 int i,j,k,ks = 1,temp,u; 19 int a[1000]; 20 while(true) { 21 for(val = sum = 0,i = 1; i <= 6; i++) { 22 scanf("%d",num+i); 23 sum += num[i]; 24 val += i*num[i]; 25 } 26 if(!sum) break; 27 printf("Collection #%d:\n",ks++); 28 if(val&1) puts("Can‘t be divided."); 29 else { 30 temp = val>>1; 31 memset(dp,0,sizeof(dp)); 32 for(i = 1; i <= 6; i++) { 33 int u = log2(num[i]); 34 for(k = 0; k <= u; k++){ 35 if(k == u){a[k] = num[i]-(1<<u)+1;} 36 else a[k] = 1<<k; 37 } 38 for(k = 0; k <= u; k++){ 39 for(j = temp; j >= a[k]*i; j--){ 40 dp[j] = max(dp[j],dp[j-a[k]*i]+a[k]*i); 41 } 42 } 43 } 44 if(dp[temp] == temp) puts("Can be divided."); 45 else puts("Can‘t be divided."); 46 } 47 printf("\n"); 48 } 49 return 0; 50 }
xtu read problem training A - Dividing,布布扣,bubuko.com
xtu read problem training A - Dividing
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/crackpotisback/p/3880300.html