hdu 6092 Rikka with Subset

本文介绍了一种解决背包问题的方法,通过不断更新物品数量并计算能够装满不同容量背包的方案数,最终输出所有可行的物品组合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

哇 这题哇 我日 哇 

其实就是不断的获得物品和物品的数量 不断的更新所有物品能装满各种容量的背包的方案数 然后一剪去就好了 这样的煞笔题我们想了好一会 哇

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <limits.h>
#include <string.h>
#include <vector>
#include <map>
#include <math.h>
#define LL long long
#define INF 2100000000
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define eps 5e-7
using namespace std;
const int maxn=(int)5e4 +30;
const int MOD=998244353;
int n,m;
LL dp[maxn];
LL num[maxn];//需要LL 吗????不需要嗷 
int main(){
#ifdef shuaishuai
    freopen("C:\\Users\\hasee\\Desktop\\a.txt","r",stdin);
    //freopen("C:\\Users\\hasee\\Desktop\\b.txt","w",stdout);
#endif
    LL tmp;
    int t;
    scanf("%d",&t);
    while(t--   ){
        scanf("%d%d",&n,&m);
        scanf("%lld",&tmp);
        dp[0]=1;for(int i=1;i<=m;i++)dp[i]=0;
        int tot=0;
        for(int i=1;i<=m;i++)
        {
            scanf("%lld",&tmp);

            int cnti=tmp-dp[i];//郝司机把它命名为 si 谁能看懂???
            //cout<<"tmp: "<<tmp<<" cnti"<<cnti<<endl;
            if(!cnti)continue;

            for(int j=0;j<cnti;j++){
                for(int k=maxn-1;k>=i;k--){
                    if(dp[k-i]) dp[k]+=dp[k-i];
                }
                num[tot++]=i;//这个数组的命名很不错 
            }
        }
        printf("%lld",num[0]);
        for(int i=1;i<tot;i++)printf(" %lld",num[i]);printf("\n"); //这是最标准的输出 致郝司机的PE代码
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/MeowMeowMeow/p/7308503.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值