POJ-3181 Dollar Dayz 【完全背包】

题目传送门

题目:输入两个数n,k,存在面值为1~k的硬币无穷多个,求这些硬币组合成总价值为n组合,问有多少种组合方式。

题解:完全背包(背包这一块我现在也不是很清楚(▼ヘ▼#))。因为数据范围超过了long long,可以用两个long long 数组去存。

AC代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define io ios::sync_with_stdio(0),cin.tie(0)
#define ms(arr) memset(arr,0,sizeof(arr))
#define inf 0x3f3f3f
typedef long long ll;
const ll mod=1e18;
const int maxn=1010;
int n,k;
ll a[maxn],b[maxn];
int main()
{
    io;
    cin>>n>>k;
    ms(a);
    ms(b);
    b[0]=1;
    for(int i=1;i<=k;i++)
    {
        for(int j=i;j<=n;j++)
        {
            a[j]=a[j]+a[j-i]+(b[j]+b[j-i])/mod;
            b[j]=(b[j]+b[j-i])%mod;
        }
    }
    if(a[n]==0)
        cout<<b[n]<<endl;
    else
        cout<<a[n]<<b[n]<<endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值