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

不应该排序的,排完序就错了。

dp[i]:存放购买前i个Pearls的最优解。

则有dp[i]=min(dp[j]+(s[i]-s[j]+10)*p[i],dp[i])

#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int t,c;
int a[];
int p[];
int dp[];
scanf("%d",&t);
while(t--){
int s[]={};
scanf("%d",&c);
for(int i=; i<c; i++){
scanf("%d %d" ,&a[i] ,&p[i]);
if(i==){
s[i]=a[i];
}else{
s[i]=s[i-]+a[i];
}
dp[i]=(s[i]+)*p[i];
}
for(int i=; i<c; i++){
for(int j=; j<=i; j++){
dp[i]=min( dp[j]+(s[i]-s[j]+)*p[i] , dp[i] );
}
}
printf("%d\n",dp[c-]);
}
return ;
}

TOJ 2888 Pearls的更多相关文章

  1. Programming pearls 编程珠玑的题目

    Programming pearls 编程珠玑的题目 这段时间有空都在看编程珠玑,很经典的一本书,一边看一边用 python 做上面的题目,我做的都放到 github 上了 https://githu ...

  2. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  3. hdu5009 Paint Pearls (DP+模拟链表)

    http://acm.hdu.edu.cn/showproblem.php?pid=5009 2014网络赛 西安 比较难的题 Paint Pearls Time Limit: 4000/2000 M ...

  4. POJ 1260 Pearls

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

  5. HDU 5009 Paint Pearls 双向链表优化DP

    Paint Pearls Problem Description   Lee has a string of n pearls. In the beginning, all the pearls ha ...

  6. POJ 1260:Pearls(DP)

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

  7. Pearls

    Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7980 Accepted: 3966 Description In ...

  8. hduacm 2888 ----二维rmq

    http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题  直接用二维rmq 读入数据时比较坑爹  cin 会超时 #include <cstdio& ...

  9. 2014 ACM/ICPC Asia Regional Xi'an Online Paint Pearls

    传说的SB DP: 题目 Problem Description Lee has a string of n pearls. In the beginning, all the pearls have ...

随机推荐

  1. AD对象DirectoryEntry本地开发

    DirectoryEntry类如果需要在本地计算机开发需要满足以下条件: 1.本地计算机dns解析必须和AD域控制器的dns保持一致,如图: 2.必须模拟身份验证,才能操作查询AD用户 /// < ...

  2. duilib入门简明教程 -- VS环境配置(2)

        会SVN和配置VS环境的请跳过此篇~          既然是入门教程,那当然得基础点,因为搜索duilib相关资料时,发现有些小伙伴到处都是编译错误,以及路径配置错误等等,还有人不知道SVN ...

  3. arcconf工具相关命令V1.0

    arcconf工具相关命令V1.0 清除当前所有raid配置 Arcconf  delete  1  array  all       #删除所有逻辑盘 Arcconf  uninit  1  all ...

  4. 以太坊系列之四: 使用atomic来避免lock

    使用atomic来避免lock 在程序中为了互斥,难免要用锁,有些时候可以通过使用atomic来避免锁, 从而更高效. 下面给出一个以太坊中的例子,就是MsgPipeRW,从名字Pipe可以看出, 他 ...

  5. 借助百度云API进行人脸识别

    前言:本篇博客是笔者第一次使用百度云api进行人脸检测,主要内容包括两部分,一是获取接口,二是借助接口进行人脸检测.笔者也是初步了解这方面的内容,也是参考了杂七杂八的博文,内容可能存在错误及其他毛病, ...

  6. networkX如何读取存储图的二进制.dat文件

    一般情况下,.dat文件存储的是图的二进制邻接矩阵. import networkx as nx G = nx.readadjlist('auth_graph.dat')

  7. PEP 8 – Style Guide for Python Code

    原文:PEP 8 – Style Guide for Python Code PEP:8 题目:Python代码风格指南 作者:Guido van Rossum, www.yszx11.cnBarry ...

  8. Python——变量的引用和函数的参数和返回值的传递方式

    变量的引用 在python中,所有的变量都是指向地址,变量本身不保存数据,而是保存数据在内存中的地址.我们用下面的程序来理解: a = 10 print(id(a)) a = 11 print(id( ...

  9. java10:基于时间的版本控制

    功能发布 从Java 10开始,采用了一种新的严格的基于时间的发布模式. 在这个新模型中,Java平台的主要版本(现称为功能版本)将每6个月(3月和9月)发布一次. 功能版本将包含语言功能,JVM功能 ...

  10. ubuntu下的pycharm4中文路径乱码

    修改字体: 设置(settings)->外观与行为(appearance & behavior) -> 外观(appearance) ->我选择的主题是Darcula 但其字 ...