hdu 1300(dp)
一个模式的dp。
Pearls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1096 Accepted Submission(s): 476
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.
2
100 1
100 2
3
1 10
1 11
100 12
1344
#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)的更多相关文章
- D - Pearls HDU - 1300 斜率dp+二分
D - Pearls HDU - 1300 这个题目也是一个比较裸的斜率dp,依照之前可以推一下这个公式,这个很好推 这个注意题目已经按照价格升序排列序,所以还是前缀和还是单调的. sum[i] 表示 ...
- hdu 3016 dp+线段树
Man Down Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 5928 DP 凸包graham
给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...
- HDU 1300 Pearls (DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1300 题目大意:珠宝店有100种不同质量的珍珠,质量越高价钱越高,为了促进销售,每买一种类型的珍珠,要 ...
- hdu 1300 Pearls(dp)
Pearls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- HDU - 1300 简单DP
题意:买珠子的方案有两种,要么单独买,价钱为该种类数量+10乘上相应价格,要么多个种类的数量相加再+10乘上相应最高贵的价格买 坑点:排序会WA,喵喵喵? 为什么连续取就是dp的可行方案?我猜的.. ...
- hdu 1300 Pearls
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1300 思路:用dp[i]表示前i种花费最低的情况,则有dp[i]=min(dp[i],dp[j+1]+(( ...
- HDU 1160 DP最长子序列
G - FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1300
http://acm.hdu.edu.cn/showproblem.php?pid=1300 这题大一就看到过,当时没读懂题目,今天再做就容易多了 题意:升序给出n个珍珠的的数量和价值,问买这些珍珠的 ...
随机推荐
- curl命令常用参数
-a/--append 上传文件时,附加到目标文件 -A/--user-agent <string> 设置用户代理发送给服务器 -anyauth 可以使用“任何”身份验证方法 -b/--c ...
- 用Jedis操作redis示例一,Key,value HashMap
简单的key,value形式 public class RedisDemo { public static void main(String[] args) { Jedis jedis = new J ...
- ExecuteScalar,ExecuteReader,ExecuteNonQuery区别
ExecuteScalar is typically used when your query returns a single value. If it returns more, then the ...
- 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 ...
- ubuntu下查找jdk安装位置
which javac 返回/usr/bin/javac file /usr/bin/javac 返回/usr/bin/javac: symbolic link to `/etc/alternativ ...
- unity, 查看资源文件类型
- mysql启动错误之mysql启动报1067错误如何解决
MYSQL启动报1067错误,系统日志中是“服务 mysql 意外停止” Mysql日志中则是:Plugin 'FEDERATED' is disabled. 解决方法: 1.在MY.INI文件中的 ...
- mysql多实例安装详解
首先说明一个场景:我的电脑是ubuntu系统,之前apt-get自动安装过mysql.这也是出现错误最多的原因之一. 安装过程,其中充斥着各种错误: 6.mkdir mysql 7.groupadd ...
- .atitit.web 推送实现解决方案集合(3)----dwr3 Reverse Ajax
.atitit.web 推送实现解决方案集合(3)----dwr3 Reverse Ajax 1. 原理实现 1 2. Page 增加配置,增加回调函数dwr.engine.setActiveRev ...
- 解决Cocos2d-x3.0、3.1 "_opendir$INODE64"symbol(s) not found错误
升级系统和XCode后.在IOS8上编译之前的项目会报例如以下错误: Undefined symbols for architecture x86_64: "_opendir$INODE64 ...