Bzoj 1042: [HAOI2008]硬币购物 容斥原理,动态规划,背包dp
1042: [HAOI2008]硬币购物
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 1747 Solved: 1015
[Submit][Status][Discuss]
Description
硬币购物一共有4种硬币。面值分别为c1,c2,c3,c4。某人去商店买东西,去了tot次。每次带di枚ci硬币,买si的价值的东西。请问每次有多少种付款方法。
Input
第一行 c1,c2,c3,c4,tot 下面tot行 d1,d2,d3,d4,s
Output
每次的方法数
Sample Input
3 2 3 1 10
1000 2 2 2 900
Sample Output
27
HINT
数据规模
di,s<=100000
tot<=1000
Source
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define LL long long
LL S,c[],d[],f[MAXN+];
LL read()
{
LL s=,fh=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')fh=-;ch=getchar();}
while(ch>=''&&ch<=''){s=s*+(ch-'');ch=getchar();}
return s*fh;
}
LL F(LL A,LL B,LL C,LL D)
{
LL ans=S;
if(A!=)ans-=(d[]+)*c[];
if(B!=)ans-=(d[]+)*c[];
if(C!=)ans-=(d[]+)*c[];
if(D!=)ans-=(d[]+)*c[];
if(ans<)return ;
return f[ans];
}
int main()
{
LL i,j,sum,tot;
for(i=;i<=;i++)c[i]=read();tot=read();
f[]=;
for(i=;i<=;i++)
{
for(j=c[i];j<=MAXN;j++)f[j]+=f[j-c[i]];
}
while(tot--)
{
for(i=;i<=;i++)d[i]=read();S=read();
sum=;
sum+=F(,,,);
sum-=F(,,,);
sum-=F(,,,);
sum-=F(,,,);
sum-=F(,,,);
sum+=F(,,,);
sum+=F(,,,);
sum+=F(,,,);
sum+=F(,,,);
sum+=F(,,,);
sum+=F(,,,);
sum-=F(,,,);
sum-=F(,,,);
sum-=F(,,,);
sum-=F(,,,);
sum+=F(,,,);
printf("%lld\n",sum);
}
return ;
}
Bzoj 1042: [HAOI2008]硬币购物 容斥原理,动态规划,背包dp的更多相关文章
- BZOJ 1042: [HAOI2008]硬币购物 容斥原理_背包_好题
Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买s i的价值的东西.请问每次有多少种付款方法. 题解: 十分喜 ...
- BZOJ 1042: [HAOI2008]硬币购物 [容斥原理]
1042: [HAOI2008]硬币购物 题意:4种硬币.面值分别为c1,c2,c3,c4.1000次询问每种硬币di个,凑出\(s\le 10^5\)的方案数 完全背包方案数? 询问太多了 看了题解 ...
- BZOJ 1042: [HAOI2008]硬币购物 容斥+背包
1042: [HAOI2008]硬币购物 Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买si的价值的东西.请 ...
- BZOJ 1042: [HAOI2008]硬币购物( 背包dp + 容斥原理 )
先按完全背包做一次dp, dp(x)表示x元的东西有多少种方案, 然后再容斥一下. ---------------------------------------------------------- ...
- bzoj 1042: [HAOI2008]硬币购物 dp+容斥原理
题目链接 1042: [HAOI2008]硬币购物 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1706 Solved: 985[Submit][ ...
- BZOJ 1042 [HAOI2008]硬币购物(完全背包+容斥)
题意: 4种硬币买价值为V的商品,每种硬币有numi个,问有多少种买法 1000次询问,numi<1e5 思路: 完全背包计算出没有numi限制下的买法, 然后答案为dp[V]-(s1+s2+s ...
- BZOJ 1042: [HAOI2008]硬币购物 (详解)(背包&容斥原理)
题面:https://www.cnblogs.com/fu3638/p/6759919.html 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚 ...
- [BZOJ 1042] [HAOI2008] 硬币购物 【DP + 容斥】
题目链接:BZOJ - 1042 题目分析 首先 Orz Hzwer ,代码题解都是看的他的 blog. 这道题首先使用DP预处理,先求出,在不考虑每种硬币个数的限制的情况下,每个钱数有多少种拼凑方案 ...
- ●BZOJ 1042 [HAOI2008]硬币购物
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1042 题解: 容斥原理,dp预处理首先跑个无限物品的背包dp求出dp[i]表示在四种物品都有 ...
随机推荐
- linux ptheard 生产者消费者
; { { printf( pthread_mutex_lock(&mutex); != g_iBufSiz ...
- [转] HTML5终极备忘大全(图片版+文字版)---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1544 一.前言兼图片 ...
- 『奇葩问题集锦』npm install 报错 node-pre-gyp ERR! node-pre-gyp -v v0.6.25
gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you ...
- php不允许用户提交空表单(php空值判断)
我们在设计提交空的评论时依然可以写入数据库,并在页面显示出来.这显然是不合理的,所以需要我们加入空值判断 可以修改代码,添加些判断: 复制代码代码如下: if(empty($_POST['name ...
- Linux使用问答
1.ubuntu 查看安装的软件包? 在终端输入 sudo dpkg -l http://vardesa.blog.hexun.com/58593247_d.html 其他:http://qiuye. ...
- statusBar显示白色字体
设置状态栏显示颜色为白色. a. 在info.plist中,添加一项,选择View controller-based status bar appearance(箭头下拉中最后一项),设置为no; b ...
- No Hibernate Session bound to thread, and configuration does not allow creat
No Hibernate Session bound to thread, and configuration does not allow creat 今天遇到这么一个错误,在网上差了很多都没有能解 ...
- Waterfall———瀑布流布局插件, 类似于 Pinterest、花瓣、发现啦。
瀑布流布局插件, 类似于 Pinterest.花瓣.发现啦. En 中文 文档 下载 下载waterfall插件最新版本. 使用 html: <div id="container&qu ...
- Python连接Redis连接配置
1. 测试连接: Python 2.7.8 (default, Oct 20 2014, 15:05:19) [GCC 4.9.1] on linux2 Type "help", ...
- xapian安装
xapian安装:$ su enter your root password # rpm -ivh http://rpm.eprints.org/rpm-eprints-org-key-1-1.noa ...