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 ...
随机推荐
- centos 重新安装python3.6之后 yum 无法使用报错
问题: $ yum File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid ...
- SQL Server 2012自动备份
SQL 2012和2008一样,都可以做维护计划,来对数据库进行自动的备份. 现在做这样一个数据库维护的计划,每天0点对数据库进行差异备份,每周日0点对数据库进行完全备份,并且每天晚上10点删除一次过 ...
- Mono for Android for Visual Studio 2010安装及试用
安装 Mono for Android for Visual Studio 2010 需要下面4个步骤: 1.安装 JDK 下载并安装 Java 1.6 (Java 6) JDK. 2.安装 Andr ...
- 以太坊系列之二: 单调时间monotime-以太坊源码学习
在程序中需要测量时间时最好使用monotime.Now()而不是time.Now(),相比之下前者更准确. 来个示例: func main() { var start, elapsed time.Du ...
- WeStrom自定义设置修改快捷键
按照下图操作,不BB: 终极懒人设置:!!!
- shell和matlab之间的参数传递
shell和matlab之间的参数传递比shell和Python之间的参数传递要简单,在matlab程序中(以.m脚本文件为例,其他程序如函数等未测试)不需要进行任何配置,直接使用即可,见下面 ...
- 【AGC010F】Tree Game 博弈论+暴力
Description 有一棵nn个节点的树,第ii条边连接ai,biai,bi,每个节点ii上有AiAi个石子,高桥君和青木君将在树上玩游戏 首先,高桥君会选一个节点并在上面放一个棋子,然后 ...
- BUAA_OO_电梯系列
电梯作业 第一次作业和第二次作业 由于我第一次作业给傻瓜电梯写了捎带所以第一次第二次作业差不多 电梯运行一个线程Elevator,输入控制一个线程Call 一个物理电梯控制表可以完成移动和进出人功能, ...
- 微信小程序获取用户手机号,服务器解码demo
原理:通过微信登陆接口wx.login得到encryptedData . iv .code.经过接口处理code得到sessionkey.最后官方demo得到解密后的手机号.(接口处理这一步也可以在 ...
- VSLAM技术框架详述
最早的SLAM雏形是在军事(核潜艇的海底定位)上的应用,主要传感器是军用雷达.SLAM技术发展到如今已经几十年,目前以激光雷达作为主传感器的SLAM技术比较稳定.可靠,仍然是主流的技术方案.但随着最近 ...