hdu6092 01背包
Rikka with Subset
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 658 Accepted Submission(s): 297
Yuta has n
positive A1−An
and their sum is m
. Then for each subset S
of A
, Yuta calculates the sum of S
.
Now, Yuta has got 2n
numbers between [0,m]
. For each i∈[0,m]
, he counts the number of i
s he got as Bi
.
Yuta shows Rikka the array Bi
and he wants Rikka to restore A1−An
.
It is too difficult for Rikka. Can you help her?
, the number of the testcases.
For each testcase, the first line contains two numbers n,m(1≤n≤50,1≤m≤104)
.
The second line contains m+1
numbers B0−Bm(0≤Bi≤2n)
.
numbers A1−An
.
It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e4+;
typedef long long LL;
LL dp[N],B[N];
int a[N];
int main(){
int n,m,T;
for(scanf("%d",&T);T--;){
memset(dp,,sizeof(dp));
memset(a,,sizeof(a));
scanf("%d%d",&n,&m);
for(int i=;i<=m;++i) scanf("%I64d",&B[i]);
dp[]=;
for(int i=;i<=m;++i){
if(dp[i]==B[i]) continue;
a[i]=B[i]-dp[i];
for(int j=;j<=a[i];++j) for(int k=m;k>=i;--k) dp[k]+=dp[k-i];
}
int i;
for(i=;i<=m;++i) if(a[i]--) {printf("%d",i);break;}
for(;i<=m;++i) while(a[i]--) printf(" %d",i);
puts("");
}
}
hdu6092 01背包的更多相关文章
- UVALive 4870 Roller Coaster --01背包
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ...
- POJ1112 Team Them Up![二分图染色 补图 01背包]
Team Them Up! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7608 Accepted: 2041 S ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- 51nod1085(01背包)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...
- *HDU3339 最短路+01背包
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)
题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- (01背包变形) Cow Exhibition (poj 2184)
http://poj.org/problem?id=2184 Description "Fat and docile, big and dumb, they look so stupid ...
- hdu3339 In Action(Dijkstra+01背包)
/* 题意:有 n 个站点(编号1...n),每一个站点都有一个能量值,为了不让这些能量值连接起来,要用 坦克占领这个站点!已知站点的 之间的距离,每个坦克从0点出发到某一个站点,1 unit dis ...
随机推荐
- 自动获取时间html代码
<button type="button" onclick="document.getElementById('demo').innerHTML = Date()& ...
- 《名侦探柯南》动画登陆bilibili
不管你看没看过.喜不喜欢,也一定听说过<名侦探柯南>这部动画,它和<火影>.<海贼王>几部动画陪伴了一代人成长的道路,而且<名侦探柯南>还是这几部动画中 ...
- Linux命令(4):touch
功能说明: touch命令参数可创建新文件以及更改文档或目录的日期时间,包括存取时间和更改时间. 命令格式: touch [选项]... 文件... 命令参数: -a 或--time=atime或 ...
- 解决layui动态追加的点击事件不起作用问题
2019独角兽企业重金招聘Python工程师标准>>> //不起作用 $('#demo').on('click', function() { layer.msg('响应点击事件'); ...
- IIS6服务器的请求流程(图文&源码)
1.IIS 7开发与管理完全参考手册 http://book.51cto.com/art/200908/146040.htm 2.Web服务IIS 6 https://technet.micro ...
- 设置 Linux 支持中文
1.首先在 command 输入 locale,可以看到 Linux 下默认的系统语言的是英文 2.vim ~/.bashrc 打开这个文件,该文件夹相当于系统配置文件 3.打开后,将后三行命令输入到 ...
- centos8-django项目部署 nginx+uwsgi
1.虚拟环境virtualenv安装 1.安装virtualenv pip3 install virtualenv 2.创建目录,把项目文件传过来 mkdir My cd My 3.创建独立运行环境- ...
- SpringBoot系列(十四)集成邮件发送服务及邮件发送的几种方式
往期推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件详解 SpringBoot系列(四)web静 ...
- MySQL连接不上
access denied for user root @localhost 解决办法: create user 'root'@'localhost' identified by '你的密码'; gr ...
- Android下拉刷新SwipeRefreshLayout简单用法
之前一直都想用下拉刷新,感觉上是庞大的工程,所以搁置了.现在学习了一下其实真的超级简单. 看了<第一行代码>以及 https://www.jianshu.com/p/3c402a9e4b7 ...