HDU 6092`Rikka with Subset 01背包变形
Rikka with Subset
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1846 Accepted Submission(s): 896
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.
2 3
1 1 1 1
3 3
1 3 3 1
1 1 1
In the first sample, A is [1,2]. A has four subsets [],[1],[2],[1,2] and the sums of each subset are 0,1,2,3. So B=[1,1,1,1]
#include<bits/stdc++.h>
#define db double
#define ll long long
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1e5+;
const int mod=1e9+;
const int MOD=mod-;
const db eps=1e-;
const int inf = 0x3f3f3f3f;
int b[N],f[N],a[N];
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
int t;
ci(t);
for(int ii=;ii<=t;ii++)
{
int n,m,c=;
ci(n),ci(m);
for(int i=;i<=m;i++) ci(b[i]);
memset(f,,sizeof(f));
f[]=;
for(int i=;i<=m;i++){//我们要加入的数字i
int v=b[i]-f[i];//加入v个i
for(int j=;j<v;j++){
a[++c]=i;
for(int k=m;k>=i;k--){
f[k]+=f[k-i];//更新当前组合的种数
}
}
}
for(int i=;i<=n;i++){
printf("%d%c",a[i],i==n?'\n':' ');
}
}
}
HDU 6092`Rikka with Subset 01背包变形的更多相关文章
- 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 2639 Bone Collector II(01背包变形【第K大最优解】)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 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
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu–2369 Bone Collector II(01背包变形题)
题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...
- hdu 6092 Rikka with Subset (集合计数,01背包)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- hdu 6092 Rikka with Subset(多重背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6092 #include <cstdio> #include <iostream> ...
- 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 ...
随机推荐
- ORACLE概要文件
oracle系统为了合理分配和使用系统的资源提出了概要文件的概念.所谓概要文件,就是一份描述如何使用系统的资源(主要是CPU资源)的配置文件.将概要文件赋予某个数据库用户,在用户连接并访问数据库服务器 ...
- windbg内存查看(d*)
d*命令 d{a|b|c|d|D|f|p|q|u|w|W} Address [/c ColumuWidth] [l Length] Address:查看address地址处的内存. ColumnWid ...
- 图解如何安装MySQL5.0
如何安装MySQL5.0数据库.. mysql-5.5.50-winx64下载地址: http://www.jb51.net/softs/363920.html 我的电脑因为提前安装了.所以需要卸载一 ...
- windows 10 安装tensorflow
人工智能一浪接一浪,随着谷歌公布tensorflow源码,尤其是支持windows 10平台的python3.5以上版本,更是让更多人都想用windows操作tensorflow. 第一次安装,也不知 ...
- 使用Groovy处理SoapUI中Json response
最近工作中,处理最多的就是xml和json类型response,在SoapUI中request里面直接添加assertion处理json response的话,可以采用以下方式: import gro ...
- IO库
IO类 C++语言不直接处理出入输出,而是通过一族定义在标准库中的类型来处理IO.这些类型支持从设备读取数据.向设备写入数据的IO操作,设备可以是文件 .控制台窗口 等.还有一些类型允许内存IO ,即 ...
- 阿里 java学习之路
https://maimai.cn/article/detail?fid=96107193&push_id=5603&share_user=http%3A%2F%2Fi9.taou.c ...
- JSP入门必读
JSP基础知识:转自老师上课梳理的笔记,希望对大家有所帮助.有什么不妥当的地方还望大家批评指正. 特别适用于JSP入门的人员使用.1.JSP [1] 简介1.1 HTML HTML擅长显示一个静 ...
- leetcode 001 Two Sun
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- jQuery EasyUI弹出确认对话框(确认操作中.....)
因为毕业设计的原因,在初期设计系统的时候没有考虑功能的正确性,所以很多的功能都没有加验证和确认的操作,给人在操作方面上有一些不好的感觉(可能失误点击后,数据就别删除,或者增加了),所以在网上找了一些资 ...