bzoj1042: [HAOI2008]硬币购物

链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1042

题意:中文题。。。

分析:首先因为4种硬币的面额是不变的而且s最大100000,所以我们先预处理出没有di限制的所有方案数,然后我们去容斥有超出的情况,超出奇数个减偶数个加。O(4*s)

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=100010;
const int MAX=151;
const int MOD1=100000007;
const int MOD2=100000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const ll INF=10000000010;
typedef unsigned long long ull;
int a[5],d[5];
ll dp[N];
int main()
{
    int i,j,k,s,tot;
    ll ans,sum;
    scanf("%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &tot);
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for (i=0;i<4;i++)
        for (j=a[i];j<N;j++) dp[j]+=dp[j-a[i]];
    while (tot--) {
        for (i=0;i<4;i++) scanf("%d", &d[i]);
        scanf("%d", &s);ans=0;
        for (i=0;i<(1<<4);i++) {
            sum=0;k=0;
            for (j=0;j<4;j++)
            if (i&(1<<j)) { sum+=(ll)a[j]*(d[j]+1);k++; }
            if (sum>s) continue ;
            if (k&1) ans-=dp[s-sum];
            else ans+=dp[s-sum];
        }
        printf("%lld\n", ans);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值