\(\\\)

Description


给出 \(N\) 种货币的面值 \(b_i\) 和个数 \(c_i\) ,求最少需要用多少个硬币凑出 \(Q\) 元钱,并输出任意一种方案。

  • \(n\le 200,Q,b_i ,c_i\le 2\times 10^4,\) 空间限制 64 M。

\(\\\)

Solution

空间计算不讲道理

如果不输出方案的话,就是一个普通的多重背包了对吧。

\(f[i]\) 表示达到体积为 \(i\) 的最少硬币数,然后直接二进制拆分就好了。

考虑转移的时候记录 \(pre\) 。

按照一般的动规方式,我们需要记录某一个状态转移自哪一个状态,这一题种,我们只需要记录转移自的上一个体积即可,若未转移指向自己。

但是发现空间爆炸。

分析转移性质,每次做背包的物品大小固定,所以转移自的状态也是确定的,所以我们只需要用一个 $bool $ 数组记录当前位置是否转移过即可。

但是依旧不明白为什么这样空间开的下 手算大小在 114 M左右

\(\\\)

Code



#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 20010
#define R register
#define gc getchar
using namespace std; inline int rd(){
int x=0; bool f=0; char c=gc();
while(!isdigit(c)){if(c=='-')f=1;c=gc();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=gc();}
return f?-x:x;
} bool g[3000][N]; int n,k,tot,b[210],c[210],f[N],bin[30]={1},cnt[210]; struct obj{int v,w,p;}s[3000]; inline void calc(int v,int w){
for(R int i=k;i>=v;--i)
if(f[i]>f[i-v]+w) g[tot][i]=1,f[i]=f[i-v]+w;
} inline void add(int v,int w,int ty){
s[++tot].v=v; s[tot].w=w;
s[tot].p=ty; calc(v,w);
} void dfs(int v,int t){
if(v==0) return;
while(!g[t][v]) --t;
cnt[s[t].p]+=s[t].w;
dfs(v-s[t].v,t-1);
} int main(){
n=rd();
memset(f,0x3f,sizeof(f)); f[0]=0;
for(R int i=1;i<=30;++i) bin[i]=(bin[i-1]<<1);
for(R int i=1;i<=n;++i) b[i]=rd();
for(R int i=1;i<=n;++i) c[i]=rd();
k=rd();
for(R int i=1;i<=n;++i){
for(R int j=0;j<=30;++j){
if(c[i]<bin[j]) break;
c[i]-=bin[j];
add(bin[j]*b[i],bin[j],i);
}
if(c[i]) add(c[i]*b[i],c[i],i);
}
printf("%d\n",f[k]);
dfs(k,tot);
for(R int i=1;i<=n;++i) printf("%d ",cnt[i]);
return 0;
}

[ POI 2005 ] Bank Notes的更多相关文章

  1. BZOJ 1531: [POI2005]Bank notes( 背包 )

    多重背包... ---------------------------------------------------------------------------- #include<bit ...

  2. bzoj1531[POI2005]Bank notes 单调队列优化dp

    1531: [POI2005]Bank notes Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 559  Solved: 310[Submit][Sta ...

  3. bzoj1531: [POI2005]Bank notes(多重背包)

    1531: [POI2005]Bank notes Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 521  Solved: 285[Submit][Sta ...

  4. bzoj1531: [POI2005]Bank notes

    Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...

  5. DSY1531*Bank notes

    Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...

  6. 1531: [POI2005]Bank notes二进制优化(c++)

    Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...

  7. 【多重背包小小的优化(。・∀・)ノ゙】BZOJ1531-[POI2005]Bank notes

    [题目大意] Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出 ...

  8. 【bzoj1531】[POI2005]Bank notes 多重背包dp

    题目描述 Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出面值 ...

  9. ●BZOJ 1531 [POI2005]Bank notes

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1531 题解: 单调队列优化多重背包DP (弱弱的我今天总算是把这个坑给填了...) 令V[i ...

随机推荐

  1. crontab not running

    there are mutliple ways to describle this issue 1. crontab not running 2. crontab not running and no ...

  2. 8VC Venture Cup 2016 - Final Round (Div2) E

    贪心.当前位置满油可达的gas station中,如果有比它小的,则加油至第一个比他小的.没有,则加满油,先到达这些station中最小的.注意数的范围即可. #include <iostrea ...

  3. DELL T110II Server如何通过RAID 级别迁移的方式在OMSA下实现磁盘阵列扩容?

    目录: RAID 转移规则说明 操作步骤 本文介绍了 通过RAID 级别转换来实现扩容的方法注意:本文相关RAID的操作,仅供在测试环境里学习和理解戴尔PowerEdge服务器RAID控制卡的功能和使 ...

  4. [React] Make Compound React Components Flexible

    Our current compound component implementation is great, but it's limited in that users cannot render ...

  5. js算法:分治法-循环赛事日程表

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...

  6. HDU 5067 Harry And Dig Machine(状压dp)

    HDU 5067 Harry And Dig Machine 思路:因为点才10个,在加上一个起点,处理出每一个点之间的曼哈顿距离,然后用状压dp搞,状态表示为: dp[i][s],表示在i位置.走过 ...

  7. mysql查看所有存储过程,函数,视图,触发器,表

    查询数据库中的存储过程和函数 方法一: select `name` from mysql.proc where db = 'your_db_name' and `type` = 'PROCEDURE' ...

  8. iOS下JSON反序列化开源库

    iOS下JSON字符串反序列化成对象.在正式的项目中比較常见.例如以下几个经常使用开源库.能够依据个人喜好任选其一: 1. JSONModel: https://github.com/icanzilb ...

  9. POJ 1651 Multiplication Puzzle 区间dp(水

    题目链接:id=1651">点击打开链 题意: 给定一个数组,每次能够选择内部的一个数 i 消除,获得的价值就是 a[i-1] * a[i] * a[i+1] 问最小价值 思路: dp ...

  10. DNNClassifier 深度神经网络 分类器

    An Example of a DNNClassifier for the Iris dataset. models/premade_estimator.py at master · tensorfl ...