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

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

Source

Northwestern Europe 2002

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int sum[1111],dp[1111],a[1111],p[1111],t,n;

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        memset(sum,0,sizeof(sum));
        memset(dp,63,sizeof(dp));
        dp[0]=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",a+i,p+i);
            sum=sum[i-1]+a;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<i;j++)
            {
                dp=min(dp,dp[j]+(sum-sum[j]+10)*p);
            }
        }
        printf("%d\n",dp[n]);
    }

return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 1260 Pearls的更多相关文章

  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 (动规)

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

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

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

  6. poj 1260 Pearls 斜率优化dp

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

  7. POJ 1260:Pearls(DP)

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

  8. POJ 1260:Pearls 珍珠DP

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

  9. 【POJ 1260】Pearls

    题 题意 有n个(n≤100)等级的珍珠,等级越高单价越高,要购买一种等级的珍珠就要多付10*单价,现在需要购买一些等级的珍珠一定数量,若买更高等级的珍珠更便宜则可以买更高等级的珍珠,求最少花费. 分 ...

随机推荐

  1. 远程办公《Remote》读书笔记:中国程序员在家上班月入过六万不是梦

    这不是一本新书,这是一本很值得中国程序员看的老书,所以我不是来做卖新书广告的:) 但它的确是一本好书,这本书在Amazon上3个business categories排第一.作者Jason Fried ...

  2. Sql Server 附加没有日志文件的数据库(.mdf)文件方法

    附加数据库,附加的时候会提醒找不到log文件 针对以上现象有两个写法的语句能解决: 写法一: USE MASTER; EXEC sp_detach_db @dbname = 'TestDB'; EXE ...

  3. [BZOJ1951][SDOI2005]古代猪文(数论好题)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1951 分析: 练习数论知识的好题,涉及到费马小定理.lucas定理.求逆元

  4. cryptDB安装分析

    cryptDB的安装脚步是用ruby语言写的,由于这里对ruby语言不熟悉,只能做简答的分析.我们先看看cryptDB的目录结构. 主要的目录有bins.doc.main.udf目录,下面我们通过分析 ...

  5. 第二十一课:js属性操作的兼容性问题

    上一课主要讲了属性的概念,用法,固有属性和自定义属性的区别,class属性操作的方法等,这一课主要讲一些有关属性操作的兼容性问题. IE6-IE8在一些表示URL的属性会返回补全的改过编码的路径,比如 ...

  6. 思甜雅--关于qq的NABCD模型分析

    个人连接:http://www.cnblogs.com/xiaoliulang/ 关于QQ的NABCD模型 N--Need 随着电脑的普及,人们在网络上进行交流的时间越来越多,由于现有的交流工具还不是 ...

  7. solr导入mysql数据库

    感谢ITeye的博主viskyzz分享的经验,笔者基本参考ta的方法.然而,解决中间出现的问题时也融入了自己的经验. 查看ta的原文请戳: http://tbwuming.iteye.com/blog ...

  8. java操作mysql中的编码问题解决

    要注意以下几点 1.在连接mysql数据库时 jdbc:mysql://localhost:3306/xiaonei?useUnicode=true&characterEncoding=utf ...

  9. JavaEE EL的一些用法

    EL 可以在指示元素中设置EL是否使用 isELIgnored="true" true是不使用 也可以在web.xml中使用 <jsp-config> <jsp- ...

  10. tomcat 的安装

    安装tomcat的前提: 首先要做的是有java环境,这里我们可以选择安装jre(java环境包).或者说安装java开发工具包ldk 我这里选择安装jdk 我们在google里搜索jdk,你就能都找 ...