一个模式的dp。

Pearls

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1096    Accepted Submission(s): 476

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
 
Source
 
Recommend
Eddy
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff
#define N 110 int dp[N][N];
int need[N],w[N];
int save[N]; int main()
{
//freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
//freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",need+i,w+i);
memset(save,,sizeof(save));
save[n]=(need[n]+)*w[n];
for(int i=n-;i>=;i--)
{
save[i]=save[i+] + need[i]*w[n];
}
int mi=INF;
for(int i=;i<=n;i++)
{
dp[][i]=save[];
if(dp[][i]<mi) mi=dp[][i];
}
for(int i=;i<n;i++)
{
int tmp=(need[i]+)*w[i];
for(int j=;j<i;j++)
{
tmp += need[j]*w[i];
}
dp[][i]=tmp+save[i+];
if(dp[][i]<mi) mi=dp[][i];
} for(int i=;i<n;i++)
for(int j=;j<=n;j++)
dp[i][j]=INF;
int tmp;
for(int p=;p<n;p++)// 选择i个点购买
{
for(int i=p;i<n;i++)
{
for(int j=p-;j<i;j++)
{
tmp=(need[i]+)*w[i]-need[i]*w[n];
for(int k=j+;k<i;k++)
tmp += need[k]*w[i]-need[k]*w[n];
dp[p][i] = min(dp[p][i],dp[p-][j]+tmp);
if(dp[p][i]<mi) mi=dp[p][i];
}
}
}
printf("%d\n",mi);
}
return ;
}

hdu 1300(dp)的更多相关文章

  1. D - Pearls HDU - 1300 斜率dp+二分

    D - Pearls HDU - 1300 这个题目也是一个比较裸的斜率dp,依照之前可以推一下这个公式,这个很好推 这个注意题目已经按照价格升序排列序,所以还是前缀和还是单调的. sum[i] 表示 ...

  2. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  3. HDU 5928 DP 凸包graham

    给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...

  4. HDU 1300 Pearls (DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1300 题目大意:珠宝店有100种不同质量的珍珠,质量越高价钱越高,为了促进销售,每买一种类型的珍珠,要 ...

  5. hdu 1300 Pearls(dp)

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

  6. HDU - 1300 简单DP

    题意:买珠子的方案有两种,要么单独买,价钱为该种类数量+10乘上相应价格,要么多个种类的数量相加再+10乘上相应最高贵的价格买 坑点:排序会WA,喵喵喵? 为什么连续取就是dp的可行方案?我猜的.. ...

  7. hdu 1300 Pearls

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1300 思路:用dp[i]表示前i种花费最低的情况,则有dp[i]=min(dp[i],dp[j+1]+(( ...

  8. HDU 1160 DP最长子序列

    G - FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1300

    http://acm.hdu.edu.cn/showproblem.php?pid=1300 这题大一就看到过,当时没读懂题目,今天再做就容易多了 题意:升序给出n个珍珠的的数量和价值,问买这些珍珠的 ...

随机推荐

  1. curl命令常用参数

    -a/--append 上传文件时,附加到目标文件 -A/--user-agent <string> 设置用户代理发送给服务器 -anyauth 可以使用“任何”身份验证方法 -b/--c ...

  2. 用Jedis操作redis示例一,Key,value HashMap

    简单的key,value形式 public class RedisDemo { public static void main(String[] args) { Jedis jedis = new J ...

  3. ExecuteScalar,ExecuteReader,ExecuteNonQuery区别

    ExecuteScalar is typically used when your query returns a single value. If it returns more, then the ...

  4. appium 1.6.3 + ios 10.2 + xcode 8.2.1 真机运行safari

    启动appium 命令: appium --address "127.0.0.1" --session-override --pre-launch --debug-log-spac ...

  5. ubuntu下查找jdk安装位置

    which javac 返回/usr/bin/javac file /usr/bin/javac 返回/usr/bin/javac: symbolic link to `/etc/alternativ ...

  6. unity, 查看资源文件类型

  7. mysql启动错误之mysql启动报1067错误如何解决

    MYSQL启动报1067错误,系统日志中是“服务 mysql 意外停止” Mysql日志中则是:Plugin 'FEDERATED' is disabled. 解决方法: 1.在MY.INI文件中的 ...

  8. mysql多实例安装详解

    首先说明一个场景:我的电脑是ubuntu系统,之前apt-get自动安装过mysql.这也是出现错误最多的原因之一. 安装过程,其中充斥着各种错误: 6.mkdir mysql 7.groupadd  ...

  9. .atitit.web 推送实现解决方案集合(3)----dwr3 Reverse Ajax

    .atitit.web 推送实现解决方案集合(3)----dwr3 Reverse Ajax 1. 原理实现 1 2. Page  增加配置,增加回调函数dwr.engine.setActiveRev ...

  10. 解决Cocos2d-x3.0、3.1 &quot;_opendir$INODE64&quot;symbol(s) not found错误

    升级系统和XCode后.在IOS8上编译之前的项目会报例如以下错误: Undefined symbols for architecture x86_64: "_opendir$INODE64 ...