Dividing
Give the value and quantity of n items and ask if they can be divided equally.
1#include <iostream>2#include <cstring>3#include <cmath>4#include <cstdio>5#include <algorithm>6#include <vector>7#include <string>8#include <map>9#include <Set>Ten#include <stack> One#include <queue> A#include <sstream> -#include <iomanip> - using namespacestd; thetypedefLong LongLL; - Const intinf=0x4fffffff; - Const Doubleexp=1e-5; - Const intms=100005; + Const intSize=1000005; - + intCnt[ms]; A intKase; at intDp[ms]; - - voidSolve () - { - intsum=cnt[0]*1+cnt[1]*2+cnt[2]*3+cnt[3]*4+cnt[4]*5+cnt[5]*6; -Memset (DP,0,sizeof(DP)); indp[0]=1; - if((sum&1)==0) to { + for(intI=0;i<6; i++) - { the intnum=Cnt[i]; * if(num==0) $ Continue;Panax Notoginseng for(intk=1;num>0; k<<=1) - { the intMul=min (k,num); + for(intj=sum/2; j>=mul* (i+1); j--) Adp[j]|=dp[j-mul* (i+1)]; the //Dp[j]=max (Dp[j],dp[j-mul*w[i]]+v[i]*mul); +num-=Mul; - } $ $ } - } -printf"Collection #%d:\n", kase++); the if((sum&1)==0&&dp[sum/2]) -printf"Can be divided.\n");Wuyi Else theprintf"Can ' t be divided.\n"); -printf"\ n"); Wu } - About intMain () $ { -Kase=1; - while(SCANF ("%d%d%d%d%d%d", &cnt[0],&cnt[1],&cnt[2],&cnt[3],&cnt[4],&cnt[5])) - { A if(cnt[0]+cnt[1]+cnt[2]+cnt[3]+cnt[4]+cnt[5]==0) + Break; the solve (); - } $ return 0; the}
Dividing multiple Backpack multiplier DP