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 ...
随机推荐
- C#秘密武器之泛型
一.简介: 很多初学者在刚开始接触泛型的时候会比较难理解泛型,在这里先把 “泛型”当作一个形容词,这样就方便理解了,因为很多东西都可以是泛型的!比如:“泛型的类”,“泛型的方法”,“泛型的接口”,“泛 ...
- 入侵者已经拿到了主机的管理员权限,请你列举几种留后门的方法:(windows和LINUX系统均可)
Webshell后门 XSS后门 远控后门&rootit(windows&LINUX) SSH后门 SHIFT终端服务器后门 系统用户账号克隆 SQL数据库扩展存储型后门 SQL数据库 ...
- 解决Odoo访问fonts.googleapis.com导致速度慢的问题
Odoo中有些css文件引用了谷歌字体,但因为谷歌服务器被墙,导致部分页面加载受影响. 解决方法如下: 360网站卫士常用前端公共库CDN服务把谷歌字体库都存到它的CDN上了,因此我们只需把样式表中谷 ...
- SSH——基于datagrid实现分页查询
1. 修改页面中datagrid的URL地址,访问action // 取派员信息表格 $('#grid').datagrid( { iconCls : 'icon-forward', fit : tr ...
- 《DirectX 9.0 3D游戏开发编程基础》必备的数学知识 读书笔记
最近在看游戏导航源码,但是看了几天感觉看不懂.里面全是一些几何运算,以及一些关于3d方面的知识.发现自己缺少3d这方面的知识,正好也想研究一下3d游戏开发的基本原理,于是决定买本书看看了,后来在ope ...
- HttpClient POST 的 UTF-8 编码问题
http://www.360doc.com/content/09/0915/15/61497_6003890.shtml不 过在实际使用中, 还是发现按照最基本的方式调用 HttpClient 时, ...
- 关于SVN提交强制加入注释
一.摘要 场景: 在这次开发项目过程中,团队中总是有人忘记添加注释. 问题: 1:其他成员不知道你提交是什么代码, 给回滚操作带来很多不必要的麻烦. 2:这个工作需要有一个人天天提醒大家在提交代码的时 ...
- 你应该将应用迁移到Spring 4的五个原因
本文来源于我在InfoQ中文站翻译的文章,原文地址是:http://www.infoq.com/cn/news/2015/12/five-reasons-to-migrate-spring4 Rafa ...
- Dapper用法小记
https://github.com/StackExchange/Dapper dapper in 查询 string sql = "SELECT * FROM SomeTable WHER ...
- [原创]如何让freeswitch转发客户端自定义的INFO消息
如何让freeswitch转发客户端自定义的INFO消息 英文概述: this article is about how to configure freeswitch to forward self ...