Hdu 6092 Rikka with Subset【背包Dp】
来源:互联网 发布:两少一宽废除知乎 编辑:程序博客网 时间:2024/05/16 23:59
Rikka with Subset
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 280 Accepted Submission(s): 113
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
Yuta hasn positive A1−An and their sum is m . Then for each subset S of A , Yuta calculates the sum of S .
Now, Yuta has got2n numbers between [0,m] . For each i∈[0,m] , he counts the number of i s he got as Bi .
Yuta shows Rikka the arrayBi and he wants Rikka to restore A1−An .
It is too difficult for Rikka. Can you help her?
Yuta has
Now, Yuta has got
Yuta shows Rikka the array
It is too difficult for Rikka. Can you help her?
Input
The first line contains a number t(1≤t≤70) , the number of the testcases.
For each testcase, the first line contains two numbersn,m(1≤n≤50,1≤m≤104) .
The second line containsm+1 numbers B0−Bm(0≤Bi≤2n) .
For each testcase, the first line contains two numbers
The second line contains
Output
For each testcase, print a single line with n numbers A1−An .
It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.
It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.
Sample Input
22 31 1 1 13 31 3 3 1
Sample Output
1 21 1 1
题目大意:
给你2^n子序列的和的分步情况【0,m】,Bi表示和为i的子序列的个数为Bi个。
让你找到一个原序列,以最小字典序输出。
思路:
我们贪心的去想,一开始的答案序列为空,如果B1>0,那么显然我们想要在结果序列中加一个1,直到当我们的答案序列中的Dp1==B1的时候,我们考虑找下一个位子,如果B2!=Dp2,那么显然我们希望在结果序列中加一个2,依次类推,我们特判一下0,然后加数的过程中拿一个背包去跑即可。
队长Ac代码(偷懒懒得再写一遍了):
#include <bits/stdc++.h>typedef long long int LL;using namespace std;const int N = 1e6+7;const int MOD = 1e9+7;const int INF = 1e9+7;inline int read(){ int x=0,f=1;char c=getchar(); for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())x=(x<<3)+(x<<1)+c-'0'; return x*f;}/********************************************/LL n,m;LL a[333],b[111111];LL h[111111];LL dp[111111];int main(){ int _ = 1,kcase = 0; for(scanf("%d",&_);_--;){ memset(dp,0,sizeof(dp)); scanf("%lld%lld",&n,&m); for(int i=0;i<=m;i++) scanf("%lld",&b[i]); for(int i=1;i<=m;i++) b[i]/=b[0];int l = 0; b[0]>>=1; while(b[0]){ a[++l]=0; b[0]>>=1; } dp[0]=1; for(int i=0;i<=m&&l<n;i++){ while(dp[i]<b[i]&&l<n){ a[++l]=i; for(int j=m;j>=i;j--) dp[j]+=dp[j-i]; } } for(int i=1;i<=l;i++) printf("%lld%c",a[i],(i==l)?'\n':' '); } return 0;}
阅读全文
0 0
- Hdu 6092 Rikka with Subset【背包Dp】
- hdu 6092 Rikka with Subset 背包dp
- hdu 6092 Rikka with Subset(dp背包)
- HDU 6092 Rikka with Subset 【dp多重背包】【好题】
- 【HDU 6092 Rikka with Subset】 思维 & 背包
- hdu 6092 Rikka with Subset 逆向背包
- HDU 6092 Rikka with Subset (背包 思维)
- HDU 6092 Rikka with Subset 反向DP
- HDU-6092 Rikka with Subset(dp)
- HDU 6092 Rikka with Subset (2017多校5-背包)
- hdu 6092 Rikka with Subset【01背包+思维】
- hdu 6092 Rikka with Subset 背包(贪心)
- 2017多校五 1008题 hdu 6092 Rikka with Subset 背包
- HDU 6092 Rikka with Subset(背包+思维)
- HDU 6092 Rikka with Subset(01背包 思维)
- HDU 6092 Rikka with Subset(完全背包)
- HDU 6092 Rikka with Subset【多重背包+贪心】
- hdu 6092 Rikka with Subset(多重背包)
- jquery实现分页
- 【BZOJ1861】书架(Splay)
- JAVA中堆和栈的区别
- Hive 之 优化
- 应用启动时,tinker的verifyclass
- Hdu 6092 Rikka with Subset【背包Dp】
- Js_Dom(3)__Dom基础<节点常用属性方法和table>
- Java知识(字符串String和StringBuffer)
- 《leetCode》:3Sum Closest
- 在Ubuntu 16.04 安装sogou 输入法详细讲解
- jdk环境变量配置
- java设计模式--多例模式(单例变形)
- 4. Zookeeper精要-数据模型
- Socket简介以及Java Socket编程