求猜存钱罐中至少有多少钱。容易知道金币总的重量,接着背包。

#include<cstdio>
#include<iostream>
using namespace std;
#define N 10010
#define M 100000000 int dp[N];
int val[],we[]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int em,fu;
scanf("%d%d",&em,&fu);
int n;
scanf("%d",&n);
for(int i=; i<n; i++)
scanf("%d%d",&val[i],&we[i]);
int ff=fu-em;
for(int i=; i<=ff; i++)
dp[i]=M;
dp[]=; for(int i=; i<n; i++)
{
for(int j=we[i]; j<=ff; j++)
dp[j]=min(dp[j],dp[j-we[i]]+val[i]);
}
if(dp[ff] ==M)printf("This is impossible.\n");
else printf("The minimum amount of money in the piggy-bank is %d.\n", dp[ff]); }
return ;
}

POJ 1384的更多相关文章

  1. poj 1384 Piggy-Bank(全然背包)

    http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...

  2. POJ 1384 POJ 1384 Piggy-Bank(全然背包)

    链接:http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...

  3. POJ 1384 Piggy-Bank (ZOJ 2014 Piggy-Bank) 完全背包

    POJ :http://poj.org/problem?id=1384 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode ...

  4. POJ 1384 Intervals (区间差分约束,根据不等式建图,然后跑spfa)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1384 Intervals Time Limit: 10000/5000 MS (Java/Others ...

  5. poj 1384 Piggy-Bank(完全背包)

    Piggy-Bank Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10830   Accepted: 5275 Descr ...

  6. POJ 1384 Piggy-Bank 背包DP

    所谓的全然背包,就是说物品没有限制数量的. 怎么起个这么intimidating(吓人)的名字? 事实上和一般01背包没多少差别,只是数量能够无穷大,那么就能够利用一个物品累加到总容量结尾就能够了. ...

  7. poj 1384完全背包

    题意:给出猪罐子的空质量和满质量,和n个硬币的价值和质量,求猪罐子刚好塞满的的最小价值. 思路:选择硬币,完全背包问题,塞满==初始化为无穷,求最小价值,min. 代码: #include<io ...

  8. POJ 1384 Piggy-Bank【完全背包】+【恰好完全装满】(可达性DP)

    题目链接:https://vjudge.net/contest/217847#problem/A 题目大意:   现在有n种硬币,每种硬币有特定的重量cost[i] 克和它对应的价值val[i]. 每 ...

  9. POJ 1384 Piggy-Bank(完全背包)

    Description Before ACM can do anything, a budget must be prepared and the necessary financial suppor ...

随机推荐

  1. 云服务器 ECS Linux IO 占用高问题排查方法

    https://help.aliyun.com/knowledge_detail/41224.html?spm=5176.7841174.2.19.uqC1as#使用 iostat 从系统纬度查看磁盘 ...

  2. stm32f107vc在IAR环境下,引用库函数的工程文件的配置方法

    stm32做开发很方便的一个原因是大家可以稍稍放松对于硬件寄存器等的设置,因为stm32有了非常丰富和实用的库函数,外设文件等等,所以我们在使用的时候可以更加关注程序开发的过程和逻辑关系.但是,在开发 ...

  3. Tuple类型

    Tuple类型类似的体现了C#中的匿名类型 var person=new { Name="Eric"; Age=18: } 调用: Console.writeline( perso ...

  4. SIFT算法的应用--目标识别之Bag-of-words模型

    原文:http://blog.csdn.net/v_JULY_v/article/details/6555899 SIFT算法的应用 -目标识别之用Bag-of-words模型表示一幅图像 作者:wa ...

  5. JavaScript随机数

    function random(start,end){ var total=start+end; return Manth.floor(Manth.random()+total-start); }

  6. JAVA基础之正则表达式

    加 ^$  整个字符串满足要求 不加部分字符串满足要求即可通过 ======================================================== \:转义字符 \d:任 ...

  7. 【阿里云产品公测】Opensearch使用体验和评测

    作者:阿里云用户outofmemory 昨天晚上收到了阿里云发的邮件,Open search可以申请公测了,于是迫不及待申请了测试,审核人员很高效,过了不到俩小时给批下来了.  很开心,于是趁今天是周 ...

  8. setcookie 之 我见

    $default_currency=get_default_currency(); $_COOKIE['currency'] = $default_currency['currency']; $_CO ...

  9. 补充:tableView优化总结

    tableView优化方式总结 (说明:一下只是我自己的小总结,会有不足,望大神指正,多谢大家了) 1 缓存 cell 的行高.目的方便第二遍访问 cell. 2 减少图片的blend 操作.包括:设 ...

  10. 【转】使用断言NSAssert()调试程序错误

    NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异 ...