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. 使用IDEA进行代码托管

    在idea菜单栏的file中打开settings/搜索git,配置path to Git executable:C:\Program Files\Git\bin\git.exe(git bash的安装 ...

  2. mac使用笔记

    1.QQ多开 MAC中登录QQ后按CMD+N组合按键即可新打开一个QQ登录窗口 2.关闭左右摇晃鼠标放大 系统偏好设置>辅助功能>显示器,去掉“摇动鼠标以定位”前面的勾即可 3.使用ctr ...

  3. 简单的音乐播放器(VS 2010 + Qt 4.8.5)

    昨天历经千辛万苦,配置好了VS 2010中的Qt环境(包括Qt for VS插件),今天决定浅浅地品味一下将两者结合进行编程的魅力. 上网查了一些资料,学习了一些基础知识,决定做一个简单的音乐播放器, ...

  4. NABCD——竞争性需求分析的框架

    最近在读邹欣老师的书<构建之法>,读到很多地方,相当有感触,有种一拍大腿“啊,他说的太对了”的感觉,但都疏于记录,今天又看到一个一拍大腿特带感的一节,决定记录下来. 竞争性需求分析的框架— ...

  5. Beta冲刺阶段

    Beta冲刺阶段 现阶段工作安排以及问题解决 Struts2框架配置 网上下载Struts 2 的框架代码,按照书上教程进行配置 遇到的问题:书上配置过程和实际操作有出入,按照书上过程无法完成配置过程 ...

  6. nginx 的中文配置详细解释

    文章转自:http://www.ha97.com/5194.html 更详细的模块参数请参考:http://wiki.nginx.org/Main #定义Nginx运行的用户和用户组 user www ...

  7. [转]JVM 内存初学 (堆(heap)、栈(stack)和方法区(method) )

    这两天看了一下深入浅出JVM这本书,推荐给高级的java程序员去看,对你了解JAVA的底层和运行机制有比较大的帮助.废话不想讲了.入主题: 先了解具体的概念:JAVA的JVM的内存可分为3个区:堆(h ...

  8. Spring控制Hibernate的缓存机制ehcache

    首先在spring.xml中进入bean <prop key="hibernate.cache.use_second_level_cache">true</pro ...

  9. BZOJ1086 [SCOI2005]王室联邦

    Description “余”人国的国王想重新编制他的国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成 员来管理.他的国家有n个城市,编号为1..n.一些城市之间有道路相连,任意两个 ...

  10. 该如何理解AMD ,CMD,CommonJS规范--javascript模块化加载学习总结

    是一篇关于javascript模块化AMD,CMD,CommonJS的学习总结,作为记录也给同样对三种方式有疑问的童鞋们,有不对或者偏差之处,望各位大神指出,不胜感激. 本篇默认读者大概知道requi ...