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;
}
题意:求一个序列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;
}
相关文章推荐
- hdu 6092 Rikka with Subset 背包dp
- HDU_6092 Rikka with Subset 【DP】
- HDU 6092 Rikka with Subset 【dp多重背包】【好题】
- Hdu 6092 Rikka with Subset【背包Dp】
- hdu 6092 Rikka with Subset
- hdu 6092 Rikka with Subset
- 【HDU 6092 Rikka with Subset】 思维 & 背包
- hdu 6092 Rikka with Subset
- Rikka with Subset HDU - 6092 (背包)
- hdu 6092 Rikka with Subset
- 2017 多校训练第五场 HDU 6092 Rikka with Subset
- HDU 6092 Rikka with Subset 贪心
- HDU 6092 Rikka with Subset
- 【多校训练】 hdu 6092 Rikka with Subset
- 17暑假多校联赛5.8 HDU 6092 Rikka with Subset
- hdu 6092 Rikka with Subset 01背包 思维
- hdu--6092--Rikka with Subset
- hdu 6092 Rikka with Subset
- 2017杭电多校第五场 1008 Rikka with Subset(动规)HDU 6092
- hdu 6092 Rikka with Subset