HDU1300
来源:互联网 发布:淘宝买韩国专辑靠谱吗 编辑:程序博客网 时间:2024/06/05 16:43
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.
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
2
2
100 1
100 2
3
1 10
1 11
100 12
Sample Output
330
1344
第二次做DP,还不是很熟练
这个题的关键我认为在于三个问题
第一个问题在于10*pj;和(a[i]-a[j])*pi的的大小
要挪动就整体全部进行挪动,单个挪动是毫无意义的。
第二个问题在于能投近的就不投远的。
第三个问题是比较是投进去的获利大,还是你投进去的地方投出来获利大。
其中状态转移方程已经把1投给2获利,投给三亏损,可是2投出去了,这个可能给考虑进去了。
j在不断增长,所以j为1的时候,1独立,2投向3的情况和1,2一起投向3 的情况已经做过比较了。
综合来说还是对我这种新手比较难理解
贴代码
#include<iostream>#include<stack>#include<queue>#include<string>#include<cmath>using namespace std;int dp[10010] ;int main(){ int n; cin >> n; while (n--) { for (int a = 0;a <= 1000;a++) { dp[a] = 1000000000; } dp[0] = 0; int a[10010], p[10010]; int num; cin >> num; a[0] = 0; for (int i = 1;i <= num;i++) { cin >> a[i] >> p[i]; a[i] = a[i - 1] + a[i]; } for (int i = 1;i <= num;i++) { for (int j = 0;j < i;j++) { dp[i] = min(dp[j] + (a[i] - a[j]+10)*p[i], dp[i]); } } cout << dp[num] << endl; } return 0;}
- hdu1300
- HDU1300
- hdu1300 Pearls
- HDU1300 动态规划
- hdu1300 Pearls--DP
- hdu1300 Pearls 【dp】
- hdu1300 pearls 【dp】
- hdu1300(水题也是dp)
- HDU1300 Pearls (动态规划)
- dp斜率优化 Pearls(Hdu1300)题解
- 缺省参数
- make menuconfig时出现 #include CURSES_LOC错误
- 找工作基础很重要(跨专业的事情要慎重啊)
- 关于全局变量控制函数的执行情况的方法!
- 获取版本号、获取手机型号
- HDU1300
- SqlServer简单优化
- 对 CNN 中 dropout layer 的理解
- listview中复用带有checkbox小记
- iOS CALayer视图图层
- 一个经典问题 (LCS)
- Android Gradle Plugin中 ApplicationVariant文件内的可用属性
- 启动apk的常用方法
- HttpStatus返回状态码