传送门 http://acm.hdu.edu.cn/showproblem.php?pid=6092
题意:求一个序列A B[i] == A的所有子集和 == i 的方案数
不难发现 加入一个数x dp[i]+=dp[i-x] 反向操作下
ACcode:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e4 + 10;
int dp[maxn],a[maxn];
int main()
{
int t;scanf("%d", &t);
for(int cas = 1; cas <= t; cas++)
{
int n, m;
scanf("%d%d", &n, &m);
for(int i = 0; i <= m; i++) scanf("%d", &dp[i]);
int cnt = 0;
for(int i = 1; i <= m; i++)
{
while(dp[i] > 0 && m > 0)
{
a[++cnt]=i;
for(int j = i; j <=m; j++)
{
dp[j]-=dp[j-i];
}
m-=i;
}
}
for(int i=1;i<n;i++) printf("%d ",a[i]);
printf("%d\n",a[n]);
}
return 0;
}