poj 1260 dp
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
题意:有c种品质不同的珠宝 ,若要买某一品质的珠宝必须支付(ai+10)*pi,可以用高品质的珠宝代替低品质的
(通过减少购买的种类来节约多支付的10个的价钱).求要买到所有目标数量的珠宝至少要花多少钱
题解:注意题目算价格的方式 注意只能由高品质代替低品质
注意题目中 given in ascending order 珠宝的品质是升序给出的
dp[i] 表示以第i个品质结尾的最优解
dp[i]=min{dp[j-1]+(sum[i]-sum[j-1]+10)*p[i]}
(sum[i]-sum[j-1]+10)*p[i]表示第j种到第i种珍珠全部替换为第i种
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cmath>
#define ll long long
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int t;
int n;
int cost[];
int qu[];
int sum[];
int dp[];
int main()
{
scanf("%d",&t);
for(int i=; i<=t; i++)
{
scanf("%d",&n);
sum[]=;
for(int j=; j<=n; j++)
{
scanf("%d %d",&cost[j],&qu[j]);
sum[j]=sum[j-]+cost[j];
dp[j]=1e9;
}
dp[]=;
for(int j=; j<=n; j++)
{
for(int k=; k<=j; k++)
dp[j]=min(dp[j],dp[k-]+(sum[j]-sum[k-]+)*qu[j]);
}
printf("%d\n",dp[n]);
}
return ;
}
poj 1260 dp的更多相关文章
- Pearls POJ - 1260 dp
题意:有n种不同的珍珠 每种珍珠的价格不同 现在给出一个采购单 标注了需要不同等级的珍珠和相对于的个数(输入按价格升序排列) 其中 价格为 (当前种类价格+10)*购买数量 这样就有一种诡异的 ...
- 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 Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8 ...
- 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 珍珠DP
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7947 Accepted: 3949 Descriptio ...
- hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)
题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...
随机推荐
- 一模 (4) day1
第一题: 题目大意:给出N个人之间转账的手续X%,求出A转给B至少要多少钱才能使B得到100元.结果保留8位小数:N<=2000 解题过程: 1.很容易看出这题的图论模型,每条边的权值就是(1- ...
- bitmap格式分析
位图(Bitmap)当然是最简单的,它Windows显示图片的基本格式,其文件扩展名为*.BMP.在Windows下,任何各式的图片文件(包括视频播放)都要转化为位图个时候才能显示出来,各种格式的图片 ...
- windows-docker开发我常用命令 docker-machine ssh default
docker-machine ssh default docker logs test sudo systemctl start docker docker tag IMAGEID ne ...
- 向量和矩阵的范数及MATLAB调用函数
范数就是长度的一种推广形式,数学语言叫一种度量.比如有一个平面向量,有两个分量来描述:横坐标和纵坐标.向量的二范数就是欧几里得意义下的这个向量的长度.还有一些诸如极大值范数,就是横坐标或者纵坐标的最大 ...
- 根据IP定位获取城市代码
public String getCityID() throws IOException{ URL url = new URL("http://61.4.185.48:81/g/" ...
- Apache虚拟主机(三)
一.启用 httpd-vhosts.conf 在httpd.conf文件中启用 在文件中搜索:Virtual hosts #Virtual hosts虚拟主机 Include conf/extra/h ...
- 03-树2 Tree Traversals Again
这题是第二次做了,两次都不是独立完成,不过我发现我第一次参考的程序,也是参考老师(陈越)的范例做出来的.我对老师给的做了小幅修改,因为我不想有全局变量的的存在,所以我多传了三个参数进去.正序遍历每次都 ...
- 实用的WPF Xml的简易读写类以及用法示例
转自:http://www.silverlightchina.net/html/study/WPF/2012/0808/17980.html 最近真是写博客写的不可收拾,今天再来一篇. 因为做一些程序 ...
- apache http client vs urlconnection
Google has deprecated HttpClient Choose an HTTP Client Most network-connected Android apps use HTTP ...
- hdu 2099
PS:因为还是不爽...继续水题...感觉这道题就是考输出.. 代码: #include "stdio.h" void cal(int a,int b); int main(){ ...