您的位置:首页 > 其它

HDU 6092 Rikka with Subset 反向DP

2017-08-08 20:57 519 查看
传送门 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
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: