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 ...
随机推荐
- Android 应用检查更新并下载
1.在Android应用当中都有应用检查更新的要求,往往都是在打开应用的时候去更新下载. 实现的方法是:服务器端提供接口,接口中可以包含在最新APK下载的URL,最新APK的VersionCode,等 ...
- java jeesite.properties配置文件属性提取
package com.thinkgem.jeesite.common.config; import java.io.UnsupportedEncodingException; import java ...
- c++实验2 顺序存储线性表
线性表顺序存储 实现了动态数组的增删改查 前驱后继 A=AUB 动态数组右移 (1)顺序表存储结构的定义(类的声明): class SeqList { protected: DataType *l ...
- DRF中的版本控制
一.为什么要有版本 某些客户端 使用低版本只维护不开发新功能 v1 主要的产品还要不断的更新迭代功能 v2 API 版本控制允许我们在不同的客户端之间更改行为(同一个接口的不同版本会返回不同的数据). ...
- swift pod 第三方库异常的处理
Xcode8—Swift开发使用Cocoapods引入第三方库异常处理方法 参考: http://www.jianshu.com/p/23f13be525a0 //podfile文件如下 platf ...
- 13. js延迟加载的方式有哪些
JS延迟加载,也就是等页面加载完成之后再加载 JavaScript 文件. JS延迟加载有助于提高页面加载速度. 一般有以下几种方式: 1)defer 属性 <script src=&q ...
- Spring Eureka的使用入门--服务端与客户端
接上篇: Eureka作为注册中心,连接服务端与客户端: 服务端: 依赖包: apply plugin: 'org.springframework.boot' apply plugin: 'io.sp ...
- pscp 命令---windows和linux之间互相拷贝文件的工具
pscp -r d:\cc root@10.0.0.8:/root/test copy d:\cc content recursively into the /root/test, contains ...
- CH2401 送礼物 双向搜索
双向搜索:把前一半的可行状态搜出来,然后sort+unique,之后搜后一半时,结束时二分一下前一半的答案,拼出一个与W尽量接近的ans来更新 ps:距LYD说前一半取n/2+2时跑的最快...不知, ...
- LeetCode934.shortest bridge【dfs+bfs】
一.题面 在给定的二维二进制数组 A 中,存在两座岛.(岛是由四面相连的 1 形成的一个最大组.) 现在,我们可以将 0 变为 1,以使两座岛连接起来,变成一座岛. 返回必须翻转的 0 的最小数目.( ...