HDU 6092:Rikka with Subset
来源:互联网 发布:lda模型 矩阵分解 编辑:程序博客网 时间:2024/05/21 19:37
Rikka with Subset
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)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 hasn positive A1−An and their sum is m . Then for each subset S of A , Yuta calculates the sum of S .
Now, Yuta has got2n numbers between [0,m] . For each i∈[0,m] , he counts the number of i s he got as Bi .
Yuta shows Rikka the arrayBi and he wants Rikka to restore A1−An .
It is too difficult for Rikka. Can you help her?
Yuta has
Now, Yuta has got
Yuta shows Rikka the array
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 numbersn,m(1≤n≤50,1≤m≤104) .
The second line containsm+1 numbers B0−Bm(0≤Bi≤2n) .
For each testcase, the first line contains two numbers
The second line contains
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.
It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.
Sample Input
22 31 1 1 13 31 3 3 1
Sample Output
1 21 1 1HintIn 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]$
Source
2017 Multi-University Training Contest - Team 5
题意:给一个数列a[1.....n],m是a数列所有元素的和,给出数列b[0.....m],b[i]代表a数列的子集中和为i的子集的个数。现在给出数列b,让你求数列a(有多解的话,字典序要最小,不过好像只有一个解。。。)。
思路:逆向DP。
可以想到b[i]是由a数列中的元素进行DP得到的。
即:
for(int i=1;i<=n;i++)
{
for(int j=m;j>=a[i];j--)b[j]+=b[j-a[i]];
}
那么我们就可以反过来求出数列a;
#include<bits/stdc++.h>using namespace std;const int maxn = 1e4+5;long long b[maxn],a[100];int main(){long long T,n,m;cin>>T;while(T--){cin>>n>>m;for(long long i=0;i<=m;i++)scanf("%lld",&b[i]);for(long long i=1;i<=m;i++){if(b[i]){a[1]=i;break;} //求出a的第一个数(因为最小的i且b[i]!=0一定代表i是a中的最小数)}long long cnt=2;for(long long i=1;i<=n;i++) //从第一个数反过来DP{for(long long j=a[i],tag=0;j<=m;j++){b[j]-=b[j-a[i]];if(b[j]>0&&tag==0)a[cnt++]=j,tag=1; //每次都要把最小的i且b[i]!=0的数加入a中}}for(long long i=1;i<=n;i++)printf("%lld%c",a[i],i==n?'\n':' ');}return 0;}
阅读全文
1 0
- hdu 6092 Rikka with Subset
- HDU 6092:Rikka with Subset
- hdu 6092 Rikka with Subset
- HDU 6092 Rikka with Subset
- HDU 6092 Rikka with Subset
- HDU 6092 Rikka with Subset
- hdu 6092 Rikka with Subset
- HDU 6092Rikka with Subset
- hdu 6092 Rikka with Subset
- HDU 6092 Rikka with Subset
- [HDU 6092] Rikka with Subset
- hdu--6092--Rikka with Subset
- HDU 6092 ( Rikka with Subset )
- HDU 6092 Rikka with Subset
- HDU 6092-Rikka with Subset
- HDU 6092 Rikka with Subset
- Rikka with Subset HDU
- Rikka with Subset HDU
- Collections框架简介
- Linux安装3.5.X版本的Python
- 简单实现Android本地音乐的播放
- 10、链式哈希表的应用-符号表
- 2017暑假训练第八天
- HDU 6092:Rikka with Subset
- SVM学习
- NYOJ 108 士兵杀敌(一)
- Java设计模式——工厂模式
- 设置postgresql的search_path
- C++ Socket 实例
- 【HDU 1024】 Max Sum Plus Plus【动态规划求最大M子段和详解-好题 】
- 简单计算器功能实现
- 2017 Multi-University Training Contest 4 1003