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

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 状态转移式为:dp[i] = min(dp[j] + (sum[i]- sum[j] + 10) * p[i]) 打表就行,递推好像也行。注意不能用sort()等等排序函数,会WA的,注意sum[i]为前i中珍珠的总数量。并不是第i种数量。
可以用结构体,也可以用pair。与UVA11400 的 Lighting System Design题相似
C++代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = ;
typedef pair<int,int> pii;
pii sen[maxn];
int sum1[maxn];
int dp[maxn];
int main(){
int T;
scanf("%d",&T);
while(T--){
int c;
scanf("%d",&c);
memset(dp,0x3f3f3f3f,sizeof(dp));
dp[] = ;
for(int i = ; i <= c; i++){
cin>>sen[i].first>>sen[i].second;
}
// sort(sen,sen + c);
memset(sum1,,sizeof(sum1));
for(int i = ; i <= c; i++){
sum1[i] = sen[i].first + sum1[i-];
}
for(int i = ; i <= c; i++){
for(int j = ; j < i; j++){
dp[i] = min(dp[i],dp[j] + (sum1[i] - sum1[j] + ) * sen[i].second);
}
}
printf("%d\n",dp[c]);
}
return ;
}

(线性结构dp )POJ 1260 Pearls的更多相关文章

  1. POJ 1260 Pearls 简单dp

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

  2. poj 1260 Pearls(dp)

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

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

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

  4. poj 1260 Pearls 斜率优化dp

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

  5. POJ 1260 Pearls

    Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6670 Accepted: 3248 Description In ...

  6. POJ 1260 Pearls (动规)

    Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7210 Accepted: 3543 Description In ...

  7. POJ 1260:Pearls(DP)

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

  8. D_S 线性结构

    线性结构的定义:若结构是非空有限集,则有且仅有一个开始结点和一个终端结点,并且所有结点都最多只有一个直接前驱和一个直接后继. 线性结构的特点: 只有一个首结点和尾结点 除首尾结点外,其他结点只有一个直 ...

  9. java数据结构--线性结构

    一.数据结构 数据结构由数据和结构两部分组成,就是将数据按照一定的结构组合起来,这样不同的组合方式有不同的效率,可根据需求选择不同的结构应用在相应在场景.数据结构大致 分为两类:线性结构(如数组,链表 ...

随机推荐

  1. Process 模块的方法

    join from multiprocessing import Process import time, os def task(name): print('%s is running' % nam ...

  2. 【CPU】理解CPU

    CPU,全称Central Processing Unit,即中央处理器. 何为CPU? 计算机必须能够自动地从主存中取出一条条指令执行,专门来执行指令的就是CPU. 一.指令的执行过程 为了理解CP ...

  3. python时间模块datetime

    datetime模块 datetime在python中比较常用,主要用来处理时间日期,使用前先倒入datetime模块.下面总结下本人想到的几个常用功能. 1.当前时间(日期.小时.字符串时....) ...

  4. Civil 3D 2017本地化中VBA程序移植到2018版中

    中国本地化包简直就是一块鸡肋, 但对于某些朋友来说还真离不了: 可惜中国本地化包的推出一直滞后, 在最新版软件出来后1年多, 本地化还不一定能够出来, 即使出来了, 也只能是购买了速博服务的用户才能得 ...

  5. POJ 2245 Addition Chains(算竞进阶习题)

    迭代加深dfs 每次控制序列的长度,依次加深搜索 有几个剪枝: 优化搜索顺序,从大往下枚举i, j这样能够让序列中的数尽快逼近n 对于不同i,j和可能是相等的,在枚举的时候用过的数肯定不会再被填上所以 ...

  6. 【BZOJ3992】【SDOI2015】序列统计 原根 NTT

    题目大意 有一个集合\(s\),里面的每个数都\(\geq0\)且\(<m\). 问有多少个长度为\(n\)的数列满足这个数列所有数的乘积模\(m\)为\(x\).答案模\(1004535809 ...

  7. jqGrid 手册 - 搜索

    搜索 类型: colModel Options Toolbar Searching Custom Searching Single field searching Advanced Searching ...

  8. HDOJ5551 Huatuo's Medicine

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5551 题目大意:... 题目思路:乱搞?模拟? #include <stdio.h> vo ...

  9. 自学Python之路-Python核心编程

    自学Python之路-Python核心编程 自学Python之路[第六回]:Python模块       6.1 自学Python6.1-模块简介    6.2 自学Python6.2-类.模块.包  ...

  10. Android应用开发资源

    Android应用设计和开发人员现在可以参考由Android用户体验(UX)团队官方发布的Android设计指南.该指南提供了开发者应该遵循的基本原则,并列出了很多细节指导,涉及设备与显示.主题.触控 ...