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减去 ...
随机推荐
- ZOJ 3652 Maze 模拟,bfs,读题 难度:2
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4842 要注意题目中两点: 1.在踏入妖怪控制的区域那一刹那,先减行动力,然后才 ...
- ARM2440 LCD实验
1. S3C2440内部LCD控制器结构图: 我们根据数据手册来描述一下这个集成在S3C2440内部的LCD控制器: a:LCD控制器由REGBANK.LCDCDMA.TIMEGEN.VIDPRCS寄 ...
- JSON:org.json的基本用法
java中用于解释json的主流工具有org.json.json-lib与gson,本文介绍org.json的应用. 官方文档: http://www.json.org/java/ http://de ...
- 交互式报表和工作报表控件Stimulsoft Reports.Fx for Java
Stimulsoft Reports.Fx for Java是一款Java平台下的报表工具控件,可以为您的应用程序添加交互式报表和工作报表.Java技术可以用于不同的平台.不同的操作系统和不同的硬件, ...
- [转]C++运算优先级列表
From:http://en.cppreference.com/w/cpp/language/operator_precedence Precedence Operator Description A ...
- 纯手写分页控件CSS+JS+SQL
Asp.net中虽然用DataPager配合ListView可以实现分页显示,但是有时候由于开发环境等问题不能用到DataPager控件,那么自己手工写一个分页控件就很有必要了,当然,最重要的是通用性 ...
- YAML 语言语法
发现很多开源的软件的配置文件都使用了这种语言来描述,据说是简单强大,很不巧,ansible也使用了这种语言来描述配置,学习ansible之前,先学习一下YAML语言. YAML基本语法规则如下: 大小 ...
- ODI中显示us7ascii字符集的测试
安装oracle DB时,选择的字符集:美国.英语.US7ASCII. 在不设置nls_lang的情况,插入中文,成功,但存进去的是乱码,select看到也是??(无论后面再怎么设置nls_lang) ...
- STM32下载显示target dll has been cancelled
使用MDK 4.74向STM32下载时出现各种错误,而且时隐时现, Internal command error.Error:Flash download failed. Target DLL has ...
- linux上安装hadoop
机器准备 物理机器 总 共4台,想配置基于物理机的hadoop集群中包括 4 个 节点: 1 个 Master , 3 个 Salve , 节点之间局域网连接,可以相互 ping 通Ip分布 为192 ...