Pearls
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7947   Accepted: 3949

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

题意是为了防止有顾客只买一种珍珠的一个,有一个购买规则即买一种珍珠的价钱为(购买的数量+10)*购买的单价,现给出要购买的珍珠的价钱和数量,在可以提高珍珠质量的前提下,求最小购买价格。

这个题一开始做成了贪心。。。结果想了一想贪心在这题上是不对的,可能前两种归一起,后两种归一起。

其实有一点是肯定的,就是如果第i种珍珠归到第j种珍珠上(当然i<j),那么第i+1,i+2...j-1种珍珠也一定归到了第j种珍珠上,所以DP的思路也就有了。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int dp1[105];//前i种珍珠的数量
int sum[105];
int dp2[105];//搞到第i种珍珠为止,花的钱
int value[105];//第i中珍珠的单价
int num; int main()
{
//freopen("i.txt","r",stdin);
//freopen("o.txt","w",stdout); int Test,i,j;
cin>>Test; while(Test--)
{
cin>>num; memset(dp1,0,sizeof(dp1));
memset(sum,0,sizeof(sum));
for(i=1;i<=num;i++)
{
dp2[i]=0x3f3f3f3f;
} for(i=1;i<=num;i++)
{
cin>>dp1[i]>>value[i];
sum[i]=sum[i-1]+dp1[i];
}
dp2[1]=(dp1[1]+10)*value[1];
for(i=1;i<=num;i++)
{
for(j=0;j<i;j++)
{
dp2[i]=min(dp2[i],dp2[j]+(sum[i]-sum[j]+10)*value[i]);
}
}
cout<<dp2[num]<<endl;
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1260:Pearls 珍珠DP的更多相关文章

  1. POJ 1260 Pearls 简单dp

    1.POJ 1260 2.链接:http://poj.org/problem?id=1260 3.总结:不太懂dp,看了题解 http://www.cnblogs.com/lyy289065406/a ...

  2. poj 1260 Pearls(dp)

    题目:http://poj.org/problem?id=1260 题意:给出几类珍珠,以及它们的单价,要求用最少的钱就可以买到相同数量的,相同(或更高)质量的珍珠. 珍珠的替代必须是连续的,不能跳跃 ...

  3. (线性结构dp )POJ 1260 Pearls

    Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10558   Accepted: 5489 Descripti ...

  4. POJ 1260 Pearls (斜率DP)题解

    思路: 直接DP也能做,这里用斜率DP. dp[i] = min{ dp[j] + ( sum[i] - sum[j] + 10 )*pr[i]} ; k<j<i  =>  dp[j ...

  5. poj 1260 Pearls 斜率优化dp

    这个题目数据量很小,但是满足斜率优化的条件,可以用斜率优化dp来做. 要注意的地方,0也是一个决策点. #include <iostream> #include <cstdio> ...

  6. POJ 1260 Pearls

    Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6670 Accepted: 3248 Description In ...

  7. POJ 1260 Pearls (动规)

    Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7210 Accepted: 3543 Description In ...

  8. POJ 1260:Pearls(DP)

    http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8 ...

  9. POJ.3624 Charm Bracelet(DP 01背包)

    POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...

随机推荐

  1. SimpleAuthenticationInfo

    public SimpleAuthenticationInfo(Object principal, Object hashedCredentials, ByteSource credentialsSa ...

  2. OpenWRT飞行计划

    openwsn飞行计划 工程wiki http://openwsn-berkeley.github.io/firmware/ 2015-12-30 Openwrt 预备 openwrt 未整理 小神器 ...

  3. WARN No appenders could be found for logger 。。。。

    对于类似与标题的警告信息,一般来说是环境在没有加载log4j的配置文件之前就读取了log4j的包. 解决方法就是先加载log4j的配置文件,然后再加载log4j的包. 另一个解决方案就是移除log4j ...

  4. other#docker

    阿里云docker镜像加速地址:https://cr.console.aliyun.com/#/accelerator docker 安装: yum install -y yum-utils devi ...

  5. CPU各个具体的指标含义

    CPU各个具体的指标含义解释如下: ①CPU(监测到的master主机上的CPU使用情况) 从图中看出,一共有五个关于CPU的指标.分别如下: 1. User User表示:CPU一共花了多少比例的时 ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-time

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  7. P1040 有几个PAT

    转跳点:

  8. 074-PHP数组元素相乘

    <?php $arr1=array(3,4,5,6,'7',TRUE); //等价于 3*4*5*6*7*1=2520 $arr2=array(3,4,5,6,'7','hello'); //等 ...

  9. Java中如何序列化一个对象(转)

    转自:http://blog.csdn.net/chx10051413/article/details/40784667 http://www.cnblogs.com/baoendemao/p/380 ...

  10. VUE- Cordova打包APP

    VUE- Cordova打包APP 现在使用vue开发的项目越来越多,使用vue开发的移动端打包就成了最大的问题.现在前端打包方案有好多种,但是综合来说,我比较喜欢用cordova来进行Android ...