Rikka with Subset
Rikka with Subset
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1442 Accepted Submission(s): 723
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 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?
Input
The first line contains a number t(1≤t≤70), 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).
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.
Sample Input
Sample Output
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]$
//题意:给出 n,m 代表有 n 个数,和为 m ,设为数列 a[i],将 a[i] 的所有子集,的和求出,记录种数,得到 b[i] ,现给出 b ,求 a
//还是太水了,这种题竟然没有一点思路,01背包的反向做法即可推出 a ,具体做法是先找到最小的不为0的 b[i] ,i 即为 a 中最小的,然后,b[j]-=b[j-i] , O(n*m)
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
#define lowbit(x) ((x)&(-x))
#define pi acos(-1.0)
#define eps 1e-8
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define LL long long
inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 100005
//Code begin...
int dp[MX]; int main()
{
int t = scan();
while (t--)
{
int n = scan(),m = scan();
dp[]=;
for (int i=;i<m+;i++)
dp[i] = scan(); vector<int> ans;
for (int i=;i<=n;i++)
{
int k;
for (int j=;j<=m;j++)
if (dp[j]!=)
{
k = j;
ans.push_back(k);
break;
}
for (int j=k;j<=m;j++)
dp[j] -= dp[j-k]; }
for (int i=;i<n;i++)
printf("%d%c",ans[i],i!=n-?' ':'\n');
}
return ;
}
Rikka with Subset的更多相关文章
- 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 6092 17多校5 Rikka with Subset(dp+思维)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- hdu 6092 Rikka with Subset(逆向01背包+思维)
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2017杭电多校第五场Rikka with Subset
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Rikka with Subset HDU - 6092 (DP+组合数)
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some mat ...
- 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 - 5829:Rikka with Subset (NTT)
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some mat ...
- hdu 6092 Rikka with Subset (集合计数,01背包)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
随机推荐
- android常用的一些属性说明
android:id --- 为控件指定相应的ID android:text --- 指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件当中的字符串 android:griv ...
- 【Python3 爬虫】09_正则表达式(re.math()、re.search()、re.sub()、全局匹配函数)
re.math()函数 从源字符串的起始位置匹配一个模式 语法:re.match(pattern, string, flag) 第一个参数代表对应的正则表达式,第二个参数代表对应的源字符,第三个参数是 ...
- 解决安装Ubuntu之后找不到无线网卡驱动的问题
为了不浇灭大家尝试ubuntu的冲动,昨天我安装了ubuntu 14.04 LTS版本号,从安装到又一次开机都非常顺利.PS:不会安装的请找教程区把,网上非常多,CSDN论坛都有. 安装之后当你奇妙的 ...
- windowns 查看端口占用
开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选&qu ...
- (016)给定一个有序数组(递增),敲代码构建一棵具有最小高度的二叉树(keep it up)
给定一个有序数组(递增),敲代码构建一棵具有最小高度的二叉树. 因为数组是递增有序的.每次都在中间创建结点,类似二分查找的方法来间最小树. struct TreeNode { int data; Tr ...
- IP报文格式及各字段意义
IP数据包由报头和数据两部分组成.报头的前一部分是固定长度,共20字节.在报头的固定部分的后面是可选部分——IP选项和填充域. 首部各字段的含义如下 1.版本 占4位,指IP协议的版本. 2 ...
- python模块学习之collections
更多信息请前往官网网址: https://docs.python.org/3.6/library/collections.html 8.3.5. namedtuple() 命名字段的元组的工场函数 命 ...
- 收集别人的一些第三方(MARK)
本文是恢复数据,数据丢失前,原文由 @shiren1118 发表于 2012-12-28,对 Ruby 社区对 iOS 开发感兴趣的朋友来说,非常有价值. iosboilerplate这个选项是比较成 ...
- Android学习之ItemTouchHelper实现RecylerView的拖拽以及滑动删除功能
今天在群里见大神们提到控件的拖动以及滑动删除的效果实现,就在网上找了资料ItemTouchHelper学习,并实现其功能.不胜窃喜之至,忍不住跟大家分享一下,如今就对学习过程做下简介.帮助大家实现这样 ...
- MFC使用自带的MSXML6.dll解析xml(开发环境vc2010)
程序是win32控制台程序 // msxml.cpp : 定义控制台应用程序的入口点. #include "stdafx.h" #include <iostream> ...