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个珍珠的的数量和价值,问买这些珍珠的 ...
随机推荐
- 使用meta属性禁用手机浏览器的缩放功能
在移动设备浏览器上,通过为视口(viewport)设置 meta 属性为 user-scalable=no 可以禁用其缩放(zooming)功能.这样禁用缩放功能后,用户只能滚动屏幕,就能让你的网站看 ...
- Ubuntu 14.10 -- 异次元软件世界
Ubuntu 14.10 中文桌面版/服务器正式版下载 - 华丽免费易于入门的 Linux 操作系统 [ 系统工具 - Linux // 2014-10-25 ] 一说到 Linux,就不得不 ...
- PhotoView
PhotoView 介绍 追求美是人的天性 PhotoView.js 灵感来自于picasa 本功能是为了解决运营对后台管理系统中用户上传的各种角度和尺寸的图片难以浏览的问题,于是花了两天时间写了这个 ...
- django Models cross file ---- 跨app引用文件
一.django 的跨app引用文件是通过import 来实现的,但是import 的路径查找和标准的import 不太一样,django里面更加方便了 二.例子 1.project 结构说明 [ji ...
- C语言的工具集
1. lint可以对c程序进行更加广泛的错误分析,lint不是缩写,它的命名是因为它像在程序中“吹毛求疵”,现在许多linux发行版都包括了它的增强版splint(Secure Programming ...
- 输入LPCWSTR类型字符串
LPCWSTR tmp = L"xxx"; char*转到LPCWSTR LPCSTR(charTmp)
- atitit.GUI图片非规则按钮跟动态图片切换的实现模式总结java .net c# c++ web html js
atitit.GUI图片非规则按钮跟动态图片切换的实现模式总结java .net c# c++ web html js 1. 图片按钮的效果总结 1 1.1. 按钮图片自动缩放的. 1 1.2. 不要 ...
- [svc]nfs客户端报错解决Stale file handle
NFS故障: 问题背景: 客户端挂载是好的.服务端磁盘满了,重新给挂了一快.客户端df -h 发现nfs挂载消失. 查看目录客户端报错:Stale file handle 现象如下: [root@n1 ...
- tornado WebSocket详解
1.什么是WebSocketwebsocket和长轮询的区别是客户端和服务器之间是持久连接的双向通信.协议使用ws://URL格式,但它在是在标准HTTP上实现的. 2.tornado的WebSock ...
- ny33 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为: 10 11 12 1 9 16 1 ...