Pearls

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 22   Accepted Submission(s) : 12
Problem 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[i],dp[j]+(sum_num(j+1...i)+10)*va[i])
 
 
 
 
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 999999999
struct pearl
{
int num,va;
}p[101]; int cmp(const pearl &p1,const pearl &p2)
{
if(p1.va<p2.va)
return 1;
else
return 0;
} int main()
{
int n;
cin>>n;
while(n--)
{
int i,j,k,c,dp[101];
cin>>c;
for(i=1;i<=c;i++)
{
cin>>p[i].num>>p[i].va;
dp[i]=INF;
}
dp[0]=0;
sort(p,p+c,cmp);
for(i=1;i<=c;i++)
{
for(j=0;j<=i;j++)
{
int total=0;
for(k=j+1;k<=i;k++)
total+=p[k].num;
if(dp[j]+(total+10)*p[i].va<dp[i])
dp[i]=dp[j]+(total+10)*p[i].va;
}
}
/*for(i=0;i<=c;i++)
cout<<dp[i]<<endl;*/
cout<<dp[c]<<endl;
}
}
 
 
 
 

HDOJ三部曲-DP-1017-pearls的更多相关文章

  1. 贪心 HDOJ 5090 Game with Pearls

    题目传送门 /* 题意:给n, k,然后允许给某一个数加上k的正整数倍,当然可以不加, 问你是否可以把这n个数变成1,2,3,...,n, 可以就输出Jerry, 否则输出Tom. 贪心:保存可能变成 ...

  2. HDOJ 1069 DP

    开启DP之路 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1069 描述一下: 就是给定N(N<=20)个方体,让你放置,求放置的最高高度,限制条件 ...

  3. hdoj 1257 DP||贪心

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. HDOJ 1260 DP

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

  5. HDOJ 3944 DP?

    尽量沿着边走距离最短.化减后 C(n+1,k)+ n - k, 预处理阶乘,Lucas定理组合数取模 DP? Time Limit: 10000/3000 MS (Java/Others)    Me ...

  6. HDOJ 5090 Game with Pearls 二分图匹配

    简单的二分图匹配: 每个位置可以边到这些数字甚至可以边 Game with Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  7. hdu 1300(dp)

    一个模式的dp. Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  9. HDU 4472 Count(数学 递归)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 Problem Description Prof. Tigris is the head of ...

随机推荐

  1. 第四周 课堂Scrum站立会议

    项目名称:连连看游戏(C#) 小组名称:4Boys 小组成员:武志远.李权.张金生.张政 站立会议内容 昨天完成的: 1.完成了游戏界面 2.做查阅关于技术方面的资料并且发布博客 3.发布项目的进度p ...

  2. javaSE之线程联合

    首先定义 : 一个线程A在占有CPU资源期间 ,可以让其他线程调用join()和本线程联合. 嗯哈,像书本这个列子: 如: B.join(); 我们称A在运行期间联合了B, 如果线程A在占有CPU资源 ...

  3. ADO.NET事务处理,初始回调函数,多张表的数据在同一个DataGridView中展示

    执行ADO.NET事务包含四个步骤,接下来以Transaction对象为例介绍. (1)调用SQLConnection对象的BeginTransaction()方法,创建一个SQLTransactio ...

  4. 下载模板,上传EXCEL

    说道SAP里对EXCEL操作的大概就是上传,下载,显示了... 下载:(文档是通过SMW0上传的)注:如果下载的时候需要填充EXCEL的值,...请参考另一篇文档,OLE CALL METHOD CL ...

  5. ABAP之DIALOG

    明天系统上线,数据一团糟,没人提BUG,无聊ING.... 今天说说SAP开发常用的DIALOG吧 一般单独的DIALOG程序可以直接建成函数组,功能组,普通报表程序. 基本都是统一的样式,主程序中I ...

  6. [转]网络时间的那些事及 ntpq 详解

    Gentoo(也许其他发行版也是?)中 "ntpq -p" 的 man page 只有简短的描述:“打印出该服务器已知的节点列表和它们的状态概要信息.” 我还没见到关于这个命令的说 ...

  7. PMP项目管理笔记 项目定义

    项目的定义 项目是为创造独特的产品,服务或成果而进行临时性的工作. 项目是组织的经营需要与战略目标服务的. PMBOK 指南描述的项目管理知识,从本质上讲,是用来管理中等或以上规模,跨部门,跨专业的目 ...

  8. 关于spring 事物传播性的研究

    spring的一大特色就是数据库事务管理方便,我们在代码中编写代码时,看不到事务的使用,关键是spring 使用了AOP进行事务拦截.   这篇文章主要介绍spring的事务传播性.   1.为什么要 ...

  9. easyui datagrid高度自适应问题

    最近在使用datagrid的时候,发现在panel中嵌入一个datagrid时,当panel缩小时,datagrid下面会有一块空白,datagrid高度不能自适应,解决方法是在datagrid外面加 ...

  10. drbd

    1.DRBD安装 1.1.安装依赖包: [java] view plaincopy yum -y install gcc kernel-devel kernel-headers flex 下载安装dr ...