Description

In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, produces a lot of jewelry with pearls in it. The Royal Pearl has its name because it delivers to the royal family of Pearlania. But it also produces bracelets and necklaces for ordinary 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

The first line of the input contains the number of test cases. Each test case starts with a line containing the number of categories c (1<=c<=100). Then, c lines follow, each with two numbers ai and pi. The first of these numbers is the number of pearls ai 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

For each test case a single line containing a single number: the lowest possible price needed to buy everything on the list. 

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的更多相关文章

  1. Pearls POJ - 1260 dp

    题意:有n种不同的珍珠 每种珍珠的价格不同  现在给出一个采购单 标注了需要不同等级的珍珠和相对于的个数(输入按价格升序排列) 其中 价格为   (当前种类价格+10)*购买数量  这样就有一种诡异的 ...

  2. POJ 1260 Pearls 简单dp

    1.POJ 1260 2.链接:http://poj.org/problem?id=1260 3.总结:不太懂dp,看了题解 http://www.cnblogs.com/lyy289065406/a ...

  3. POJ 1260:Pearls(DP)

    http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8 ...

  4. poj 1260 Pearls(dp)

    题目:http://poj.org/problem?id=1260 题意:给出几类珍珠,以及它们的单价,要求用最少的钱就可以买到相同数量的,相同(或更高)质量的珍珠. 珍珠的替代必须是连续的,不能跳跃 ...

  5. (线性结构dp )POJ 1260 Pearls

    Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10558   Accepted: 5489 Descripti ...

  6. POJ 1260 Pearls (斜率DP)题解

    思路: 直接DP也能做,这里用斜率DP. dp[i] = min{ dp[j] + ( sum[i] - sum[j] + 10 )*pr[i]} ; k<j<i  =>  dp[j ...

  7. poj 1260 Pearls 斜率优化dp

    这个题目数据量很小,但是满足斜率优化的条件,可以用斜率优化dp来做. 要注意的地方,0也是一个决策点. #include <iostream> #include <cstdio> ...

  8. POJ 1260:Pearls 珍珠DP

    Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7947   Accepted: 3949 Descriptio ...

  9. hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)

    题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...

随机推荐

  1. 从协议VersionedProtocol开始

    VersionedProtocol协议是Hadoop的最顶层协议接口的抽象:5--3--3共11个协议,嘿嘿 1)HDFS相关 ClientDatanodeProtocol:client与datano ...

  2. SharePoint 2013 Nintex Workflow 工作流帮助(九)

    博客地址 http://blog.csdn.net/foxdave 前叙:假期结束了,知道为什么假期如此短暂吗?因为假期的每天只有半天.春节过完了,新的一年开始了,大家或许之前在新年的时候都许下了自己 ...

  3. SharePoint开发 - 自定义导航菜单(二)母版页的菜单应用

    博客地址 http://blog.csdn.net/foxdave 接上篇点击打开链接 本篇叙述在母版页中应用之前的配置信息生成菜单,主要涉及到母版页的自定义,并应用了第三方控件库DevExpress ...

  4. winform错误提示 :窗口类名无效(Window class name is not valid)

    winfrom 程序在 xp 操作系统上报错提示 窗口类名无效(Window class name is not valid) 解决方法 注释 Program类 里 这句 Application.En ...

  5. JavaScript 时间特效 显示当前时间

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  6. 第一课 Hello

    using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; ...

  7. Airbase-ng帮助

    Airbase-ng 1.2 rc2 - (C) 2008-2014 Thomas d'Otreppe  Original work: Martin Beck  http://www.aircrack ...

  8. JS对于Android和IOS平台的点击响应的适配

    IOS点击事件 Click 300毫秒点击延迟 解决办法: 参考:http://cuiqingcai.com/1687.html 可判断设备 if (/(iPhone|iPad|iPod|iOS)/i ...

  9. HDU 2157

    http://acm.hdu.edu.cn/showproblem.php?pid=2157 求A到B经过K个点的方案数 http://www.matrix67.com/blog/archives/2 ...

  10. 【转】Entity Systems

    “Favour composition over inheritance” If you haven’t already read my previous post on the problems o ...