BZOJ1531/POI2005 Bank notes
来源:互联网 发布:细说php 编辑:程序博客网 时间:2024/06/06 02:55
裸的多重背包,利用二进制进行优化:
假设有12枚面额为3的硬币,可以把它转化为
面值为3,6,12,15的硬币分别1枚.这样就把物品总数减少到log件.
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int M=205;const int S=15;const int maxm=2e4+5;int dp[maxm],v[M*S],f[M*S],n,m,cnt[M],A[M],tot=0;void Min(int &x,int y){ if(x==-1||x>y)x=y;}inline void rd(int &res){ res=0;char c; while(c=getchar(),c<48); do res=(res<<1)+(res<<3)+(c^48); while(c=getchar(),c>=48);}int main(){ memset(dp,-1,sizeof(dp)); int i,j,k; rd(n); for(i=1;i<=n;i++)rd(A[i]); for(i=1;i<=n;i++)rd(cnt[i]); rd(m); for(i=1;i<=n;i++){ int x,y=cnt[i]; for(j=S-1;j>=0;j--){ if((1<<j)<=cnt[i]){ x=j;break; } } for(j=x-1;j>=0;j--){ f[++tot]=(1<<j); v[tot]=f[tot]*A[i]; y-=f[tot]; } if(y){ f[++tot]=y; v[tot]=f[tot]*A[i]; } } dp[0]=0; for(i=1;i<=tot;i++){ for(j=m-v[i];j>=0;j--){ if(~dp[j])Min(dp[j+v[i]],dp[j]+f[i]); } } printf("%d\n",dp[m]); return 0;}
0 0
- [BZOJ1531] [POI2005]Bank notes
- BZOJ1531/POI2005 Bank notes
- 【BZOJ1531】[POI2005]Bank notes【多重背包】
- BZOJ1531——[POI2005]Bank notes
- bzoj1531[POI2005]Bank notes 多重背包
- 【BZOJ 1531】 [POI2005]Bank notes
- bzoj 1531: [POI2005]Bank notes
- BZOJ 1531 POI2005 Bank notes 多重背包
- BZOJ 1531: [POI2005]Bank notes 多重背包
- bzoj 1531: [POI2005]Bank notes 单调队列优化多重背包
- 【BZOJ】【P1531】【POI2005】【Bank notes】【题解】【二进制优化背包】【300T留念】
- bzoj1531
- bank
- bank
- bank
- [POI2005]Dwu
- Notes
- notes
- 尺取法学习笔记
- BOZJ1528/POI 2005Toy Cars
- BZOJ1529/POI2005 Piggy banks
- #早安,努力#10.27
- RFS的web自动化验收测试--变量的声明、赋值及其使用
- BZOJ1531/POI2005 Bank notes
- Morphia 学习一 注解
- 从0.25到1.0,中小企业Mesos网络和存储的填坑实践
- Docker Swarm学习笔记(二)
- 洛谷1311 选择客栈
- BZOJ1532/POI2005 Dicing
- 面向对象的好处
- BZOJ153/POI2005 A Journey to Mars
- BZOJ1534/POI2005 Fibonacci sums