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减去 ...
随机推荐
- 前端必须掌握30个CSS3选择器
也许你已经学会了CSS的三个简单常用的选择器:#ID,.class,标签选择器,可是这些就足够了吗?随着CSS3的到来,作为前端开发者需要掌握下面三十个基本的选择器,这样才可以在平时开发中得心用手. ...
- appjs desktop2
var express = require('express');var path = require('path');var favicon = require('serve-favicon');v ...
- $where $options: 'g','i'
db.classes.update({"count":{$gt:20}},{$set:{"name":"c4"}},false,false) ...
- centos=>gsutil,iptables
sudo apt-get remove --purge gsutil sudo easy_install -U pip sudo pip2 install gsutil gsutil ls gs:/ ...
- Python中subprocess学习
subprocess的目的就是启动一个新的进程并且与之通信. subprocess模块中只定义了一个类: Popen.可以使用Popen来创建进程,并与进程进行复杂的交互.它的构造函数如下: subp ...
- K2采购管理解决方案在线研讨会
会议时间: 2013-10-31 15:00-17:00 注册地址:http://k2.gensee.com/webcast/site/livelogin 采购作为现代产业链中的一个基础环节,它的管 ...
- Spring学习笔记之Bean的实例化
一.bean的实例化方法有3种, 1.构造器实例化 2.静态工厂方法实例化 3.实例工厂方法实例化 二.用构造器来实例化 <bean id="ShunDao" class=& ...
- APC to USB
from :http://www.allpinouts.org/index.php/APC_USB_cable_schematic connector or cable wiring APC part ...
- linux学习笔记2:linux 下java开发的软件安装
一.java ee开发环境的搭建 1.jdk的安装步骤 (1)首先必须要有安装文件,具体的可以去相关网站上下载,并制作iso文件 (2)将制作的iso文件挂载到linux系统上,并在虚拟机上将iso文 ...
- SimpleDateFormat格式化日期
SimpleDateFormat格式化日期 import java.text.SimpleDateFormat;import java.util.Date;public class test { pu ...