标签:ons amp otto output osi des vector numbers diff
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 typedef long long ll; 5 const int maxn = 5e5+500; 6 int n,m; 7 ll cnt[maxn]; 8 ll sum[maxn]; 9 int num[maxn]; 10 int main() 11 { 12 //freopen("de.txt","r",stdin); 13 int T; 14 scanf("%d",&T); 15 while (T--){ 16 memset(sum,0,sizeof sum); 17 memset(num,0,sizeof num); 18 scanf("%d%d",&n,&m); 19 for (int i=0;i<=m;++i) 20 scanf("%lld",&cnt[i]); 21 num[0]=0; 22 sum[0]=cnt[0]; 23 while((1<<num[0])<cnt[0]) num[0]++; 24 for (int i=1;i<=m;++i){ 25 num[i]=(cnt[i]-sum[i])/sum[0];//num[i]*sum[0]+sum[i]=cnt[i] 26 for (int j=1;j<=num[i];++j){//一个一个的加入几个 27 for (int k=m;k>=i;--k){//完全背包思想更新sum 28 sum[k]+=sum[k-i]; 29 } 30 } 31 } 32 vector<int> vec; 33 for (int i=0;i<=m;++i){ 34 for (int j=0;j<num[i];++j) 35 vec.push_back(i); 36 } 37 for (int i=0;i<vec.size();++i) 38 printf("%d%c",vec[i],i==(vec.size()-1)?‘\n‘:‘ ‘); 39 } 40 return 0; 41 }
hdu 6092 Rikka with Subset (集合计数,01背包)
标签:ons amp otto output osi des vector numbers diff
原文地址:http://www.cnblogs.com/agenthtb/p/7338105.html