http://poj.org/problem?id=1260

Pearls
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8474   Accepted: 4236

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 题意:题意比较难以解释,大概就是要用最小的花费去买完所有珍珠,珍珠可以分块购买(每次购买的价格是最高级的珍珠的价格)或者单类购买,每一次购买都要加上10个此次购买的最高级珍珠的价格(最高级的珍珠是输入时越靠后的,并不是最贵的,一开始排了序,然后错了,千万注意)
 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define MAXN 1010 struct node
{
int a,p;
}c[MAXN];
int dp[MAXN],sum[MAXN]; bool cmp(node a,node b)
{
return a.p<b.p;
} int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
memset(dp,,sizeof(dp));
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++){
scanf("%d%d",&c[i].a,&c[i].p);
sum[i]=sum[i-]+c[i].a;
}
// sort(c+1,c+n+1,cmp);
int res,tmp,ans=;
for(int i=;i<=n;i++){
tmp=;
for(int j=;j<=i;j++){
tmp=min( dp[j-]+(sum[i]-sum[j-]+)*c[i].p,tmp );
}
dp[i]=tmp;
}
printf("%d\n",dp[n]);
}
return ;
}

												

POJ 1260:Pearls(DP)的更多相关文章

  1. POJ 2192 :Zipper(DP)

    http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

  2. POJ 1260:Pearls 珍珠DP

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

  3. HDU 1260:Tickets(DP)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  4. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  5. POJ 3858 Hurry Plotter(DP)

    Description A plotter is a vector graphics printing device that connects to a computer to print grap ...

  6. Codeforces Gym101341K:Competitions(DP)

    http://codeforces.com/gym/101341/problem/K 题意:给出n个区间,每个区间有一个l, r, w,代表区间左端点右端点和区间的权值,现在可以选取一些区间,要求选择 ...

  7. HDU 5791:Two(DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=5791 Two Problem Description   Alice gets two sequences A ...

  8. POJ - 2385 Apple Catching (dp)

    题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...

  9. POJ 1191 棋盘分割(DP)

    题目链接 题意 : 中文题不详述. 思路 : 黑书上116页讲的很详细.不过你需要在之前预处理一下面积,那样的话之后列式子比较方便一些. 先把均方差那个公式变形, 另X表示x的平均值,两边平方得 平均 ...

随机推荐

  1. [GeoServer]重拾GeoServer之安装篇

    GeoServer的项目是一个完整的Java(J2EE)系统,现实了OpenGIS联盟的网络功能服务器规范和网络覆盖服务器规范,并且集成了Web地图服务器. 在大三的时候WebGIS课程中老师讲解过一 ...

  2. ios-控件的frame_center_bounds简单介绍

    frame 例如一个button按钮控件的frame frame是一个结构体,frame表示了button在它的父控件view中的位置---origin 以及---size origin也是一个结构体 ...

  3. ios常见细节问题-删掉main.storyboard程序启动屏幕变黑-崩溃

    删掉程序默认的main.storyboard文件后,程序启动崩溃 如图所示.原因是删掉main.storyboard文件后没有在info.plist文件里面设置 删掉main.storyboard后程 ...

  4. Oracle Flashback Technologies (总)

    Oracle Flashback Technologies Oracle 9i中增加了闪回查询技术,闪回查询为数据库提供了一种简单.强大.完全无干扰从人为错误中恢复的机制.通过闪回查询,用户可以查看过 ...

  5. scp noneed passwd

    经常在不同linux机器之间互相scp拷文件,每次总是要输入密码才可行. 通过ssh-keygen生成公钥,在两台机器之间互相建立信任通道即可. 假设本地机器client,远程机器为server. 1 ...

  6. tornado中使用Mako模版

    tornado是一个优秀的python的开源web 框架,框架本身的性能确实很好,但是他自带的模版只能说是一般般.关于tornado的详细信息可以直接到管网参考. http://www.tornado ...

  7. PostgreSQL中美元符号引用的字符串常量

    虽然用于指定字符串常量的标准语法通常都很方便,但是当字符串中包含了很多单引号或反斜线时很难理解它,因为每一个都需要被双写.要在这种情形下允许可读性更好的查询,PostgreSQL提供了另一种被称为“美 ...

  8. 树形DP(统计直径的条数 HDU3534)

    分析:首先树形dp(dfs计算出每个点为根节点的子树的最长距离和次长距离),然后找出L=dis[u][0]+dis[u][1]最长的那个点u,然后在以u为根节点dfs,统计长度为L的条数:具体做法:把 ...

  9. 20145207《Java程序设计》第7周学习总结

    教材学习内容总结 一.Lambda -使用Lambda的特性可以去除重复的信息,以取得语法的简洁,增加程序代码的表达性.Lambda表达式本身是中性的,不代表任何类型的实例,同样的Lambda表达式, ...

  10. acm pc^2的配置与使用

    -------------------------------------------------------------------------------------- !!! 转载请注明: 转自 ...