POJ 1260-Pearls 动态规划
来源:互联网 发布:小米2s刷windows 编辑:程序博客网 时间:2024/06/04 00:31
题目来源:http://124.205.79.250/JudgeOnline/problem?id=1260
解题报告:
一开始觉得可以用贪心算法,后来发现是不对的,比方说对如下的测试数据:
10 10
5 15
10 23
就不行了。还是要用动态规划来解
我设f[k]代表只买前k个,可以花的最少的钱。
则
f[k]=min( (a1+a2+...+ak+10)*pk, f[1]+(a2+...+ak+10)*pk, ... ,f[k-1]+(ak+10)*pk )
显然,最后的f[n]就是所需求的。
附录:
Pearls
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3231 Accepted: 1520
Description
In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, produces a lot of jewelry with pearls in it. The Royal Pearl has its name because it delivers to the royal family of Pearlania. But it also produces bracelets and necklaces for ordinary people. Of course the quality of the pearls for these people is much lower then the quality of pearls for the royal family.In Pearlania pearls are separated into 100 different quality classes. A quality class is identified by the price for one single pearl in that quality class. This price is unique for that quality class and the price is always higher then the price for a pearl in a lower quality class.
Every month the stock manager of The Royal Pearl prepares a list with the number of pearls needed in each quality class. The pearls are bought on the local pearl market. Each quality class has its own price per pearl, but for every complete deal in a certain quality class one has to pay an extra amount of money equal to ten pearls in that class. This is to prevent tourists from buying just one pearl.
Also The Royal Pearl is suffering from the slow-down of the global economy. Therefore the company needs to be more efficient. The CFO (chief financial officer) has discovered that he can sometimes save money by buying pearls in a higher quality class than is actually needed.No customer will blame The Royal Pearl for putting better pearls in the bracelets, as long as the
prices remain the same.
For example 5 pearls are needed in the 10 Euro category and 100 pearls are needed in the 20 Euro category. That will normally cost: (5+10)*10+(100+10)*20 = 2350 Euro.Buying all 105 pearls in the 20 Euro category only costs: (5+100+10)*20 = 2300 Euro.
The problem is that it requires a lot of computing work before the CFO knows how many pearls can best be bought in a higher quality class. You are asked to help The Royal Pearl with a computer program.
Given a list with the number of pearls and the price per pearl in different quality classes, give the lowest possible price needed to buy everything on the list. Pearls can be bought in the requested,or in a higher quality class, but not in a lower one.
Every month the stock manager of The Royal Pearl prepares a list with the number of pearls needed in each quality class. The pearls are bought on the local pearl market. Each quality class has its own price per pearl, but for every complete deal in a certain quality class one has to pay an extra amount of money equal to ten pearls in that class. This is to prevent tourists from buying just one pearl.
Also The Royal Pearl is suffering from the slow-down of the global economy. Therefore the company needs to be more efficient. The CFO (chief financial officer) has discovered that he can sometimes save money by buying pearls in a higher quality class than is actually needed.No customer will blame The Royal Pearl for putting better pearls in the bracelets, as long as the
prices remain the same.
For example 5 pearls are needed in the 10 Euro category and 100 pearls are needed in the 20 Euro category. That will normally cost: (5+10)*10+(100+10)*20 = 2350 Euro.Buying all 105 pearls in the 20 Euro category only costs: (5+100+10)*20 = 2300 Euro.
The problem is that it requires a lot of computing work before the CFO knows how many pearls can best be bought in a higher quality class. You are asked to help The Royal Pearl with a computer program.
Given a list with the number of pearls and the price per pearl in different quality classes, give the lowest possible price needed to buy everything on the list. Pearls can be bought in the requested,or in a higher quality class, but not in a lower one.
Input
The first line of the input contains the number of test cases. Each test case starts with a line containing the number of categories c (1<=c<=100). Then, c lines follow, each with two numbers ai and pi. The first of these numbers is the number of pearls ai needed in a class (1 <= ai <= 1000).
The second number is the price per pearl pi in that class (1 <= pi <= 1000). The qualities of the classes (and so the prices) are given in ascending order. All numbers in the input are integers.
The second number is the price per pearl pi in that class (1 <= pi <= 1000). The qualities of the classes (and so the prices) are given in ascending order. All numbers in the input are integers.
Output
For each test case a single line containing a single number: the lowest possible price needed to buy everything on the list.
Sample Input
22100 1100 231 101 11100 12
Sample Output
3301344
Source
- POJ 1260-Pearls 动态规划
- poj 1260 Pearls 【动态规划】
- poj 1260 Pearls 动态规划
- Pearls(动态规划)
- 动态规划-Pearls
- 【POJ1260】Pearls (动态规划)
- zoj 1563 Pearls 动态规划
- HDU1300 Pearls (动态规划)
- acm pku 1260 Pearls的动态规划算法实现
- poj 1260 Pearls
- POJ 1260 Pearls
- POJ 1260 Pearls DP
- Poj 1260 Pearls
- POJ 1260 Pearls
- poj 1260 pearls
- poj-1260-Pearls-dp
- POJ 1260 Pearls
- POJ 1260 Pearls
- 设计模式学习21 State
- 网站测试基本方法-24. 连接速度测试
- 谷歌中国新麻烦 - 代理商退出 合作伙伴分手
- History(历史)命令用法15 例
- LOST退役文
- POJ 1260-Pearls 动态规划
- 雅虎部分网络访问中断 官方称与微软测试无关
- 是谁在我的心里打了个结(七)投标书
- JSP、信息、
- JAVA学习笔记2
- uExportXls.pas(使用二进制流技术快速导出Excel文件)
- iPad香港开售:数百人排队,半小时售罄
- typedef 相关
- 擎泰SK6213量产工具_PDT_20100209A