HDU1114-基础dp&完全背包-F
来源:互联网 发布:小米电视软件推荐 编辑:程序博客网 时间:2024/06/07 11:26
https://vjudge.net/contest/170788#problem/F
给定一个存钱罐初始重量和装了钱币的重量,
给定每种钱币的 重量和价值。
问你最小的价值是多少。
可知是 正好装下,dp[0]变成0,其余无穷大。
若是不要求装满,则全部为0
然后是完全背包了
#include <iostream>#include <cstdio>#include <cstdio>using namespace std;const int maxn=200000;int dp[maxn];int c[maxn];int v[maxn];int main(){ int t; int m,n; int k; scanf("%d",&t); while(t--){ scanf("%d%d",&m,&n); m=n-m; if(m<=0){ puts("This is impossible."); continue; } scanf("%d",&k); for(int i=0;i<k;i++) scanf("%d%d",&v[i],&c[i]); for(int i=0;i<=m;i++) dp[i]=1e9; dp[0]=0; for(int i=0;i<k;i++) for(int j=c[i];j<=m;j++) dp[j]=min(dp[j],dp[j-c[i]]+v[i]); if(dp[m]==1e9) puts("This is impossible."); else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[m]); } return 0;}
阅读全文
0 0
- HDU1114-基础dp&完全背包-F
- HDU1114 【DP入门之完全背包】
- HDU1114 完全背包变形
- hdu1114 & poj1384 完全背包
- hdu1114完全背包
- HDU1114完全背包
- hdu1114(完全背包)
- hdu1114完全背包
- hdu1114(完全背包)
- HDU1114(完全背包)
- hdu1114 完全背包
- hdu1114 完全背包
- HDU1114完全背包模板
- hdu1114 Piggy-Bank 完全背包
- Piggy-Bank hdu1114 完全背包
- hdu1114 Piggy-Bank (完全背包)
- HDU1114(完全背包问题)
- 简单的完全背包HDU1114
- 【POJ1840】Eqs
- 欢迎使用CSDN-markdown编辑器
- 暑期集训之Bear and Three Balls
- 1064. Complete Binary Search Tree (30)
- 隐式intent
- HDU1114-基础dp&完全背包-F
- java.lang.NoClassDefFoundError: org/springframework/web/context/request/async/CallableProcessingInte
- 【POJ2752】seek the name,seek the fame
- Java学习第八天
- 关于RedisTemplate和StringRedisTemplate
- Keil综合(03)_map文件全解析
- JavaScript 常用方法总结
- 3.等待和通知(Waiting and Notification)
- java-数据类型和逻辑运算