hdu 6092 Rikka with Subset (集合计数,01背包)
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 is 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?
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).
It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.
#include <bits/stdc++.h> using namespace std;
typedef long long ll;
const int maxn = 5e5+;
int n,m;
ll cnt[maxn];
ll sum[maxn];
int num[maxn];
int main()
{
//freopen("de.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--){
memset(sum,,sizeof sum);
memset(num,,sizeof num);
scanf("%d%d",&n,&m);
for (int i=;i<=m;++i)
scanf("%lld",&cnt[i]);
num[]=;
sum[]=cnt[];
while((<<num[])<cnt[]) num[]++;
for (int i=;i<=m;++i){
num[i]=(cnt[i]-sum[i])/sum[];//num[i]*sum[0]+sum[i]=cnt[i]
for (int j=;j<=num[i];++j){//一个一个的加入几个
for (int k=m;k>=i;--k){//完全背包思想更新sum
sum[k]+=sum[k-i];
}
}
}
vector<int> vec;
for (int i=;i<=m;++i){
for (int j=;j<num[i];++j)
vec.push_back(i);
}
for (int i=;i<vec.size();++i)
printf("%d%c",vec[i],i==(vec.size()-)?'\n':' ');
}
return ;
}
hdu 6092 Rikka with Subset (集合计数,01背包)的更多相关文章
- hdu 6092 Rikka with Subset(逆向01背包+思维)
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 6092`Rikka with Subset 01背包变形
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu 6092 Rikka with Subset 01背包 思维
dp[i][j]表示前i个元素,子集和为j的个数.d[i][j] = d[i][j] + d[i-1][j-k] (第i个元素的值为k).这里可以优化成一维数组 比如序列为 1 2 3,每一步的dp值 ...
- HDU 6092 Rikka with Subset
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 6092 Rikka with Subset(dp)
http://acm.hdu.edu.cn/showproblem.php?pid=6092 题意: 给出两个数组A和B,A数组一共可以有(1<<n)种不同的集合组合,B中则记录了每个数出 ...
- 2017 ACM暑期多校联合训练 - Team 5 1008 HDU 6092 Rikka with Subset (找规律)
题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...
- hdu 6092 Rikka with Subset(多重背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6092 #include <cstdio> #include <iostream> ...
- HDU 6092:Rikka with Subset(dp)
分析 很多个较小的数字可以随机组合成较大的数字,所以B数组从小到大开始遍历,除了空集,最小的那个存在的个数对应的数字必然是a数组中的数字. 每求出这一部分之后,更新后续的B序列. 分析完后,主要的难点 ...
- hdu 2126 Buy the souvenirs 二维01背包方案总数
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- PCB六层板学习(一)
一.原理图的网表导出及版本转换 安装Cadence后,打开RK3288的原理图. 首先点击rk3288-mid.dsn >> 然后有一个Create netlist的图标(当然咋Tools ...
- 「长乐集训 2017 Day8」修路 (斯坦纳树)
题目描述 村子间的小路年久失修,为了保障村子之间的往来,AAA君决定带领大家修路. 村子可以看做是一个边带权的无向图GGG, GGG 由 nnn 个点与 mmm 条边组成,图中的点从 1∼n1 \si ...
- vue数据渲染、条件判断及列表循环
1.数据渲染 {{msg}} <template> <div id="app"> {{msg}} </div> </template&g ...
- 部署Jenkins完整记录
Jenkins通过脚本任务触发,实现代码的自动化分发,是CI持续化集成环境中不可缺少的一个环节.下面对Jenkins环境的部署做一记录.-------------------------------- ...
- Windows-Windows下使用Linux系统(WSL)
Install Windows Subsystem for Linux (WSL) on on Windows 10 | Microsoft Docs WSL(Windows Subsystem fo ...
- 20150721—HTML的定位 JS (转)
本文转载于:http://blog.csdn.net/xuantian868/article/details/3116442 HTML:scrollLeft,scrollWidth,clientW ...
- 用 Flask 来写个轻博客 (24) — 使用 Flask-Login 来保护应用安全
Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 扩展阅读 用户登录帐号 用户登录状态 Flask-Login 使用 F ...
- GET and POST
有待补充:
- b/s 起点
1.Web前端: JavaScript (1)脚本语言.JavaScript是一种解释型的脚本语言,C.C++等语言先编译后执行,而JavaScript是在程序的运行过程中逐行进行解释. (2)基于对 ...
- Android深度探索-卷1第一章心得体会
本章介绍了安卓系统移植与驱动开发的概述,安卓的系统架构有四层:1 Linux内核,2 c/c++代码库, 3 Android SDK API, 4 应用程序 在读的过程中看到了专业名词,查了查,长点 ...