Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 44409   Accepted: 16184

Description

A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the machine has a supply of nk bills. For example,

N=3, n1=10, D1=100, n2=4, D2=50, n3=5, D3=10

means the machine has a supply of 10 bills of @100 each, 4 bills of @50 each, and 5 bills of @10 each.

Call cash the requested amount of cash the machine should deliver and write a program that computes the maximum amount of cash less than or equal to cash that can be effectively delivered according to the available bill supply of the machine.

Notes: 
@ is the symbol of the currency delivered by the machine. For instance, @ may stand for dollar, euro, pound etc. 

Input

The program input is from standard input. Each data set in the input stands for a particular transaction and has the format:

cash N n1 D1 n2 D2 ... nN DN

where 0 <= cash <= 100000 is the amount of cash requested, 0 <=N <= 10 is the number of bill denominations and 0 <= nk <= 1000 is the number of available bills for the Dk denomination, 1 <= Dk <= 1000, k=1,N. White spaces can occur freely between the numbers in the input. The input data are correct.

Output

For each set of data the program prints the result to the standard output on a separate line as shown in the examples below. 

Sample Input


Sample Output


Hint

The first data set designates a transaction where the amount of cash requested is @735. The machine contains 3 bill denominations: 4 bills of @125, 6 bills of @5, and 3 bills of @350. The machine can deliver the exact amount of requested cash.

In the second case the bill supply of the machine does not fit the exact amount of cash requested. The maximum cash that can be delivered is @630. Notice that there can be several possibilities to combine the bills in the machine for matching the delivered cash.

In the third case the machine is empty and no cash is delivered. In the fourth case the amount of cash requested is @0 and, therefore, the machine delivers no cash.

AC代码

 

POJ 1276 Cash Machine(完全背包模板题)的更多相关文章

  1. Poj 1276 Cash Machine 多重背包

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26172   Accepted: 9238 Des ...

  2. POJ 1276 Cash Machine(多重背包的二进制优化)

    题目网址:http://poj.org/problem?id=1276 思路: 很明显是多重背包,把总金额看作是背包的容量. 刚开始是想把单个金额当做一个物品,用三层循环来 转换成01背包来做.T了… ...

  3. [poj 1276] Cash Machine 多重背包及优化

    Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver ap ...

  4. POJ 1276 Cash Machine(单调队列优化多重背包)

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38986   Accepted: 14186 De ...

  5. poj 1276 Cash Machine(多重背包)

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33444   Accepted: 12106 De ...

  6. POJ 1276 Cash Machine

    Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24213 Accepted: 8476 Descrip ...

  7. POJ 3624 Charm Bracelet(01背包模板题)

    题目链接 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 52318   Accepted: 21912 Descriptio ...

  8. 【转载】poj 1276 Cash Machine 【凑钱数的问题】【枚举思路 或者 多重背包解决】

    转载地址:http://m.blog.csdn.net/blog/u010489766/9229011 题目链接:http://poj.org/problem?id=1276 题意:机器里面共有n种面 ...

  9. POJ 1276 Cash Machine -- 动态规划(背包问题)

    题目地址:http://poj.org/problem?id=1276 Description A Bank plans to install a machine for cash withdrawa ...

随机推荐

  1. go 中string[0]到底是rune还是byte?

    好像没区别,对吧? 来看个全面的对比: package main import ( "fmt" "reflect") func main(){ asci:=&q ...

  2. 1-Consul系列文章

    使用Consul做服务发现的若干姿势 Consul的反熵 [Consul]Consul架构-简介

  3. spark源码解析--Shuffle输出追踪者--MapOutputTracker

    Shuffle输出追踪者--MapOutputTracker 这个组件作为shuffle的一个辅助组件,在整个shuffle模块中具有很重要的作用.我们在前面一系列的分析中,或多或少都会提到这个组件, ...

  4. [Vscode插件] 自动编译项目中的Sass文件为CSS

    插件名 : Live Sass Compiler 今天在VSCode中发现了一个自动watch项目目录下sass文件的插件,摆脱了在控制台中进行手动watch的繁琐. 安装好以后点击右下角即可自动编译 ...

  5. 01. MySQL8.0 MAC-OS-X安装

    目录 MySQL8.0 MAC-OS-X安装 8.0较与5.7变化 下载 安装 启动 登录查看数据库 安装后mysql文件分布 MySQL8.0 MAC-OS-X安装 换mac啦,搭建开发环境,安装m ...

  6. Nginx 反向代理功能-实现Nginx tcp负载均衡

    Nginx 反向代理功能-实现Nginx tcp负载均衡 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.

  7. PHP实例:获取操作系统、IP、地理位置、浏览器、等信息

    获取访客操作系统以及浏览器语言 <?php function GetBrowser(){ if(!empty($_SERVER['HTTP_USER_AGENT'])){ $br = $_SER ...

  8. Discuz!开发之时间处理函数dgmdate()详解

    使用过Discuz!的朋友都会知道Discuz!的时间可以显示成多少秒前.多少分钟前.几个小时前.几天前等等,而不是单纯的显示标准时间,这样的时间显示方式就更显得人性化了!   那么Discuz!是如 ...

  9. Python input() 函数

    Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用来获 ...

  10. zzulioj - 2623: 小H的作业题

    题目链接:http://acm.zzuli.edu.cn/problem.php?id=2623 题目描述        期末考试即将来临,同学们都积极的在图书馆复习.今天小H也来到图书馆复习,小H掏 ...