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. JMeter Bean Shell

    1.什么是bean Shell BeanShell是一种脚本语言,一种完全符合java语法的java脚本语言,并且又拥有自己的一些语法和方法,beanShell是一种松散类型的脚本语言(这点和JS类似 ...

  2. 【bzoj2500】幸福的道路 树形dp+单调队列

    Description 小T与小L终于决定走在一起,他们不想浪费在一起的每一分每一秒,所以他们决定每天早上一同晨练来享受在一起的时光. 他们画出了晨练路线的草图,眼尖的小T发现可以用树来描绘这个草图. ...

  3. Deploy Flask app to Apache on Windows

    内容已过期,分割线以下为原文存档. 故事背景 这次我需要将一个Flask应用部署到本地的Windows服务器上.操作系统是64位的,程序是基于Python 3开发的,大体就是这样. 部署选项 根据Fl ...

  4. 一、pytest的介绍和安装

    需要针对一个项目系统开发一套UI自动化测试脚本,自己结合着学习,采用了pytest去实现,这里留下记录. 什么是pytest pytest 是一个非常成熟的全功能的Python测试框架 可以胜任uni ...

  5. redis锁

    1.引入依赖: <!--使用redis客户端需要用到的包 --> <dependency> <groupId>redis.clients</groupId&g ...

  6. win7/win8/win10 系统

    WIN7/WIN8/WIN10 系统安装 http://www.windows7en.com/Win7/18572.html

  7. django中的setting最佳配置小结

    Django settings详解 1.基础 DJANGO_SETTING_MODULE环境变量:让settings模块被包含到python可以找到的目录下,开发情况下不需要,我们通常会在当前文件夹运 ...

  8. SPOJ - COT2 离线路径统计

    题意:求\(u\)到\(v\)的最短路径的不同权值种类个数 树上莫队试水题,这一篇是上篇的弱化部分,但可测试以下结论的正确性 设\(S(u,v)\):\(u-v\)最短路径所覆盖的点集 \(S(u,v ...

  9. HDU - 4035 循环型概率DP

    题解待会在上 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring ...

  10. drf之序列化器的使用

    一.序列化器-Serializer 作用: 1. 序列化,序列化器会把模型对象转换成字典,经过response以后变成json字符串 2. 完成数据校验功能 3. 反序列化,把客户端发送过来的数据,经 ...