(线性结构dp )POJ 1260 Pearls
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10558 | Accepted: 5489 |
Description
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 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
Sample Input
2
2
100 1
100 2
3
1 10
1 11
100 12
Sample Output
330
1344 状态转移式为:dp[i] = min(dp[j] + (sum[i]- sum[j] + 10) * p[i]) 打表就行,递推好像也行。注意不能用sort()等等排序函数,会WA的,注意sum[i]为前i中珍珠的总数量。并不是第i种数量。
可以用结构体,也可以用pair。与UVA11400 的 Lighting System Design题相似
C++代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = ;
typedef pair<int,int> pii;
pii sen[maxn];
int sum1[maxn];
int dp[maxn];
int main(){
int T;
scanf("%d",&T);
while(T--){
int c;
scanf("%d",&c);
memset(dp,0x3f3f3f3f,sizeof(dp));
dp[] = ;
for(int i = ; i <= c; i++){
cin>>sen[i].first>>sen[i].second;
}
// sort(sen,sen + c);
memset(sum1,,sizeof(sum1));
for(int i = ; i <= c; i++){
sum1[i] = sen[i].first + sum1[i-];
}
for(int i = ; i <= c; i++){
for(int j = ; j < i; j++){
dp[i] = min(dp[i],dp[j] + (sum1[i] - sum1[j] + ) * sen[i].second);
}
}
printf("%d\n",dp[c]);
}
return ;
}
(线性结构dp )POJ 1260 Pearls的更多相关文章
- POJ 1260 Pearls 简单dp
1.POJ 1260 2.链接:http://poj.org/problem?id=1260 3.总结:不太懂dp,看了题解 http://www.cnblogs.com/lyy289065406/a ...
- poj 1260 Pearls(dp)
题目:http://poj.org/problem?id=1260 题意:给出几类珍珠,以及它们的单价,要求用最少的钱就可以买到相同数量的,相同(或更高)质量的珍珠. 珍珠的替代必须是连续的,不能跳跃 ...
- POJ 1260 Pearls (斜率DP)题解
思路: 直接DP也能做,这里用斜率DP. dp[i] = min{ dp[j] + ( sum[i] - sum[j] + 10 )*pr[i]} ; k<j<i => dp[j ...
- poj 1260 Pearls 斜率优化dp
这个题目数据量很小,但是满足斜率优化的条件,可以用斜率优化dp来做. 要注意的地方,0也是一个决策点. #include <iostream> #include <cstdio> ...
- POJ 1260 Pearls
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6670 Accepted: 3248 Description In ...
- POJ 1260 Pearls (动规)
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7210 Accepted: 3543 Description In ...
- POJ 1260:Pearls(DP)
http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8 ...
- D_S 线性结构
线性结构的定义:若结构是非空有限集,则有且仅有一个开始结点和一个终端结点,并且所有结点都最多只有一个直接前驱和一个直接后继. 线性结构的特点: 只有一个首结点和尾结点 除首尾结点外,其他结点只有一个直 ...
- java数据结构--线性结构
一.数据结构 数据结构由数据和结构两部分组成,就是将数据按照一定的结构组合起来,这样不同的组合方式有不同的效率,可根据需求选择不同的结构应用在相应在场景.数据结构大致 分为两类:线性结构(如数组,链表 ...
随机推荐
- 十、docker扩展
一.memcached docker pull memcached docker run --name my-memcache -d -p 11211:11211 memcached telnet 1 ...
- How to reset macOS Icon Cache
find . -name cuthead.txt find /private/var/folders/ -name 'com.apple.dock.iconcache' -delete find /p ...
- 创建一个UWP 打包签名
Create a certificate for package signing 2017/2/8 3 min to read [ Updated for UWP apps on Windows 10 ...
- Nginx geo模块
geo 模块默认编译进nginx 可以通过--without-http_geo_module禁用 Syntax: geo [$address] $variable { ... } Default: — ...
- AMD直奔5nm!这一步棋下得妙
AMD今年将推出采用7nm工艺的第二代EPYC霄龙.第三代Ryzen锐龙处理器,其中后者已经在CES 2019上公开首秀,性能追评i9-9900K,功耗则低得多. 虽然被称为“女友”的GlobalFo ...
- 解决Maven依赖报错问题
问题现象:从svn上签下源代码,本地执行打包命令,提示如下错误: [ERROR] Failed to execute goal on project dddwriter: Could not reso ...
- POJ 1125-Stockbroker Grapevine-最短路
裸最短路 /*--------------------------------------------------------------------------------------*/ // H ...
- BZOJ2434 [NOI2011] 阿狸的打字机 【树链剖分】【线段树】【fail树】【AC自动机】
题目分析: 画一下fail树,就会发现就是x的子树中属于y路径的,把y剖分一下,用线段树处理 $O(n*log^2 n)$. 代码: #include<bits/stdc++.h> usi ...
- 用贝叶斯定理解决三门问题并用Python进行模拟(Bayes' Rule Monty Hall Problem Simulation Python)
三门问题(Monty Hall problem)也称为蒙提霍尔问题或蒙提霍尔悖论,出自美国的电视游戏节目<Let’s Make a Deal>.问题名字来自该节目的主持人蒙提·霍尔(Mon ...
- java使用Rome解析Rss的实例(转)
Rome简介 Rome是为RSS聚合而开发的开源包,它可以支持0.91.0.92.0.93.0.94.1.0.2.0,可以说rss的版本基本上都支持了. Rss简介 RSS是站点用来和其他站点之间共享 ...