HDOJ1300 Pearls 简单dp
来源:互联网 发布:8097端口 编辑:程序博客网 时间:2024/06/08 09:57
Pearls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2769 Accepted Submission(s): 1380
Problem 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.
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
Northwestern Europe 2002
Recommend
Eddy | We have carefully selected several similar problems for you: 1227 1224 1080 1160 1081
先计算单独购买所需的花费,再跟连续购买的方案作对比
代码如下:
#include <iostream>#include <ctime>#include <algorithm>#include <cmath>using namespace std;const int maxn = 105;const int inf = 1<<25;int c,a[maxn],p[maxn],dp[maxn],cnt[maxn];int main(){ std::ios::sync_with_stdio(false); int t,i,j,k; cin >> t; while(t--) { cin >> c; cnt[0] = 0; dp[0] = 0; for (i=1; i<=c; i++) { cin >> a[i] >> p[i]; cnt[i] = cnt[i-1] + a[i]; //方便后续计算要购买的珠宝数量 dp[i] = dp[i-1] + (a[i] + 10) * p[i]; //先假设都是单独购买 } //for (i=1; i<=c; i++) cout << cnt[i] << endl; for (i=2; i<=c; i++) { for (j=0; j<i; j++) { dp[i] = min (dp[i] , dp[j] + (cnt[i] - cnt [j] + 10) * p[i] ); } } cout << dp[c] << endl; } return 0;}
阅读全文
0 0
- HDOJ1300 Pearls 简单dp
- POJ 1260 Pearls (简单DP)
- POJ 1260 简单dp问题 Pearls
- Pearls--DP
- POJ1260 Pearls DP
- POJ 1260 Pearls DP
- poj-1260-Pearls-dp
- hdu 1300 Pearls(dp)
- hdu 1300 Pearls DP
- ZOJ 1563 Pearls(DP)
- HDU 1300 Pearls(DP)
- poj 1260Pearls DP
- Pearls - POJ 1260 dp
- HDU 1300 Pearls(DP)
- hdu5009 Paint Pearls DP
- 【DP】HDU-1300 Pearls
- POJ 1260-Pearls(dp)
- Hdoj 1300 Pearls 【DP】
- Kolakoski
- 如何将本地Xcode代码上传到GitHub上
- CSS vertical-align属性的用法
- html标准流中的浮动元素之空间零占用
- KMP算法
- HDOJ1300 Pearls 简单dp
- Just do it待解决
- 杭电 Kolakoski
- rtmpdump的librtmp时间戳有问题,服务器会断开连接
- NXP-EVB-P6UL linux根文件系统定制手册《一》
- JS中一种实现sleep函数的方案
- react-native插件
- 微信浏览器、手机版浏览器、pc版浏览器网站的缓存怎么清理? 比较好的三点解决方案
- ECharts地图颜色-选中颜色设置