TOJ 2888 Pearls
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
不应该排序的,排完序就错了。
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的更多相关文章
- Programming pearls 编程珠玑的题目
Programming pearls 编程珠玑的题目 这段时间有空都在看编程珠玑,很经典的一本书,一边看一边用 python 做上面的题目,我做的都放到 github 上了 https://githu ...
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- hdu5009 Paint Pearls (DP+模拟链表)
http://acm.hdu.edu.cn/showproblem.php?pid=5009 2014网络赛 西安 比较难的题 Paint Pearls Time Limit: 4000/2000 M ...
- POJ 1260 Pearls
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6670 Accepted: 3248 Description In ...
- HDU 5009 Paint Pearls 双向链表优化DP
Paint Pearls Problem Description Lee has a string of n pearls. In the beginning, all the pearls ha ...
- POJ 1260:Pearls(DP)
http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8 ...
- Pearls
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7980 Accepted: 3966 Description In ...
- hduacm 2888 ----二维rmq
http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题 直接用二维rmq 读入数据时比较坑爹 cin 会超时 #include <cstdio& ...
- 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 ...
随机推荐
- HTML & CSS设计与构建网站 ([美]达科特) PDF原版
HTML & CSS 设计与构建网站采用有别于许多传统编程书籍的新颖编排方式,将使您收到事半功倍的学习效果.每一页都在短小精悍的示例代码的引导下,简明直观.直截了当地阐述一个新主题. < ...
- cdq分治略解
前言 陌上花开,可缓缓归矣 --吴越王 寓意:意思是:田间阡陌上的花开了,你可以一边赏花,一边慢慢回来. 隐意:春天都到了,你怎么还没有回来.形容吴越王 ...
- 使用IIS服务器部署网页,需要开启服务里的“ASP.NET 状态服务”
否则会提示“请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器端口相同.如果服务器位于远程计算机上,请检查 HKEY_LOCAL_MACHI ...
- Java面向对象之异常(异常处理方式)
一.基础概念 (1)异常:Java程序在运行时期发生的不正常情况. Java就按照面向对象的思想对不正常情况进行描述和对象的封装. (2)异常问题分类: (Throwable:定义对于问题共性的功能. ...
- query flot 直方图上显示对应的y值
方法1:使用在图上加 相对定位的 div 提示对应的直方图数量. 具体实现:获取直方图上所有的点,得到y值和对应的坐标位置,插入相对div 主要js代码:plot 为对应的图对象 //初始化柱状图数据 ...
- express + vue 项目搭建
最近建了一个node服务端加vue前端的项目 安装node :npm install node 安装express :npm install express -g (-g全局安装) 构建express ...
- opencv学习笔记(六)---图像梯度
图像梯度的算法有很多方法:sabel算子,scharr算子,laplacian算子,sanny边缘检测(下个随笔)... 这些算子的原理可参考:https://blog.csdn.net/poem_q ...
- (STM32F4) Real-time Clock
老實說Real-time Clok這項功能,我也只有在PC和手機上有見過,其他的應用產品上我也很少見到. 言歸正傳在STM32F4 RTC這項功能在IC內部就有內建,在早期的8051是如果要做RCT是 ...
- java 连接 Redis
使用 jedis-2.9.0.jar 包 连接 Docker 中的 Redis 容器. package redisTest; /** * @Author:YangLianjun * @Descript ...
- kotlin 注意的地方
1 . kotlin let 用法: let(val -> ) 注意:这 -> 后面不能有 花括号!!!! 2 . kotlin 中 如果使用了 @Transactional 注解.请让 ...