POJ 1260:Pearls 珍珠DP
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 7947 | Accepted: 3949 |
Description
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
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
Sample Input
2
2
100 1
100 2
3
1 10
1 11
100 12
Sample Output
330
1344
题意是为了防止有顾客只买一种珍珠的一个,有一个购买规则即买一种珍珠的价钱为(购买的数量+10)*购买的单价,现给出要购买的珍珠的价钱和数量,在可以提高珍珠质量的前提下,求最小购买价格。
这个题一开始做成了贪心。。。结果想了一想贪心在这题上是不对的,可能前两种归一起,后两种归一起。
其实有一点是肯定的,就是如果第i种珍珠归到第j种珍珠上(当然i<j),那么第i+1,i+2...j-1种珍珠也一定归到了第j种珍珠上,所以DP的思路也就有了。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int dp1[105];//前i种珍珠的数量
int sum[105];
int dp2[105];//搞到第i种珍珠为止,花的钱
int value[105];//第i中珍珠的单价
int num; int main()
{
//freopen("i.txt","r",stdin);
//freopen("o.txt","w",stdout); int Test,i,j;
cin>>Test; while(Test--)
{
cin>>num; memset(dp1,0,sizeof(dp1));
memset(sum,0,sizeof(sum));
for(i=1;i<=num;i++)
{
dp2[i]=0x3f3f3f3f;
} for(i=1;i<=num;i++)
{
cin>>dp1[i]>>value[i];
sum[i]=sum[i-1]+dp1[i];
}
dp2[1]=(dp1[1]+10)*value[1];
for(i=1;i<=num;i++)
{
for(j=0;j<i;j++)
{
dp2[i]=min(dp2[i],dp2[j]+(sum[i]-sum[j]+10)*value[i]);
}
}
cout<<dp2[num]<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1260:Pearls 珍珠DP的更多相关文章
- 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 题意:给出几类珍珠,以及它们的单价,要求用最少的钱就可以买到相同数量的,相同(或更高)质量的珍珠. 珍珠的替代必须是连续的,不能跳跃 ...
- (线性结构dp )POJ 1260 Pearls
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10558 Accepted: 5489 Descripti ...
- 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 ...
- POJ.3624 Charm Bracelet(DP 01背包)
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...
随机推荐
- sessionManager配置
在sessionManager配置的时候,有两个属性, 在这个类中,cacheManager是要注入到sessionDao中的,但要求sessionDao实现CacheManagerAware接口 C ...
- MySQL学习之SQL基础(一)DML
DML(data Manipulation language) INSERT DELETE UPDATE SELECT INSERT mysql> desc emp; +----------+- ...
- 题解:luogu P1247
大概没你们说得复杂吧...... \(Part\;1\) \(Nim\)游戏 大家都对异或和感到懵逼吧(排除大佬),其实很简单,用\(SG\)函数打表计算即可解决: 抛个板子: void get_sg ...
- 彻底理解JavaScript中的this
this 是 JavaScript 语言的一个关键字. 它是函数运行时,在函数体内自动生成的一个对象,只能在函数体内使用. 函数的不同使用场合,this 有不同的值.总的来说,this 就是函数运行时 ...
- SmartAssembly .net混淆后,无法找到部分类型
两种解决方式: 1,在vs项目引用中,COM 嵌入互操作类型, 全部设为false. 2, 在混淆选项中,排除所有 引有的 外部COM类
- MySQL如何获取时间戳
时间戳函数:current_timestamp() 将时间列格式设为timestamp,设定其默认值为CURRENT_TIMESTAMP. 插入一条新纪录,数据库就会自动在时间列存储当前时间.
- 吴裕雄--天生自然java开发常用类库学习笔记:StringBuffer
public class StringBufferDemo01{ public static void main(String args[]){ StringBuffer buf = new Stri ...
- Ican协议建立连接我的感悟
有一个情形我突然之间想明白了. 注意下面情形: 假设节点A与节点B已经 正常的建立了连接,并且进行了通讯. 假设 节点B收到了 节点A 的 &q ...
- POJ2533:Longest Ordered Subsequence
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 37454 Acc ...
- require(): open_basedir restriction in effect. File(/www/wwwroot/xcx/zerg/thinkphp/start.php) is not within the allowed path(s): (/www/wwwroot/xcx/zerg/public/:/tmp/:/proc/) in /www/wwwroot/xcx/zerg/p
解决方法: 在如下文件增加一项(如图所示) 在如下文件增加一项(如图所示): #php文件采用fastcgi解析并设置参数 location ~ \.php { try_files ...