POJ 1260:Pearls(DP)
http://poj.org/problem?id=1260
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8474 | Accepted: 4236 |
Description
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
Output
Sample Input
2
2
100 1
100 2
3
1 10
1 11
100 12
Sample Output
330
1344 题意:题意比较难以解释,大概就是要用最小的花费去买完所有珍珠,珍珠可以分块购买(每次购买的价格是最高级的珍珠的价格)或者单类购买,每一次购买都要加上10个此次购买的最高级珍珠的价格(最高级的珍珠是输入时越靠后的,并不是最贵的,一开始排了序,然后错了,千万注意)
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define MAXN 1010 struct node
{
int a,p;
}c[MAXN];
int dp[MAXN],sum[MAXN]; bool cmp(node a,node b)
{
return a.p<b.p;
} int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
memset(dp,,sizeof(dp));
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++){
scanf("%d%d",&c[i].a,&c[i].p);
sum[i]=sum[i-]+c[i].a;
}
// sort(c+1,c+n+1,cmp);
int res,tmp,ans=;
for(int i=;i<=n;i++){
tmp=;
for(int j=;j<=i;j++){
tmp=min( dp[j-]+(sum[i]-sum[j-]+)*c[i].p,tmp );
}
dp[i]=tmp;
}
printf("%d\n",dp[n]);
}
return ;
}
POJ 1260:Pearls(DP)的更多相关文章
- POJ 2192 :Zipper(DP)
http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
- POJ 1260:Pearls 珍珠DP
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7947 Accepted: 3949 Descriptio ...
- HDU 1260:Tickets(DP)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- POJ 3858 Hurry Plotter(DP)
Description A plotter is a vector graphics printing device that connects to a computer to print grap ...
- Codeforces Gym101341K:Competitions(DP)
http://codeforces.com/gym/101341/problem/K 题意:给出n个区间,每个区间有一个l, r, w,代表区间左端点右端点和区间的权值,现在可以选取一些区间,要求选择 ...
- HDU 5791:Two(DP)
http://acm.hdu.edu.cn/showproblem.php?pid=5791 Two Problem Description Alice gets two sequences A ...
- POJ - 2385 Apple Catching (dp)
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...
- POJ 1191 棋盘分割(DP)
题目链接 题意 : 中文题不详述. 思路 : 黑书上116页讲的很详细.不过你需要在之前预处理一下面积,那样的话之后列式子比较方便一些. 先把均方差那个公式变形, 另X表示x的平均值,两边平方得 平均 ...
随机推荐
- chrome 下载插件包及离线安装
最近需要测试http rest服务,由于chrome插件的轻便,首先想到了用chrome插件,在google商店找到Advanced Rest Client,用了一阵感觉不错. 于是项目组其他同事也要 ...
- checkbox判断选中
$("input[type='checkbox']").is(':checked')
- Oracle Hang Manager
名词术语1.Cross Boundary Hang 交叉边界hang.在12.1.0.1中,hang manager可以检测database和asm之间的hang.2.Deadlock or Clos ...
- Azure billing 分析
昨天把西欧的2012的VM删掉,在北美新建一个2008的VM,装了sql2005 express 在C盘,这样存储就变成2个位置了,西欧和美国,然后放在那里不操作一天,发现billing多了很多, S ...
- R语言putty中直接使用X11(Xming)绘图
1.下载Xming地址 http://pan.baidu.com/s/1o6ilisU,安装,推荐默认安装在C盘,推荐快捷方式放在与putty快捷方式同一个文件夹: 2.打开putty,在SSH的X1 ...
- SC-控制Windows服务的命令
Windows自带一个控制服务的命令-SC,下面用Terminal Service做个简单例子: 查询Terminal Service的配置 C:\Users\jackie.chen>sc qc ...
- 安装windowbuilder错误一例
eclipse是3.7版本,安装了windowbuilder,大致步骤如下: http://www.cnblogs.com/gladto/archive/2011/07/21/2112836.html ...
- 一个新人对JavaScript的内容简单介绍
JavaScript 1.基本的数据类型:字符串 小数 整数 时间日期 布尔型等. 2.变量: JS定义变量通通都是用var开头,var里面可以放任何东西(如:小数,整数,字符串,时间日期等等 ...
- 树形DP+RMQ+单调队列(Bob’s Race HDU4123)
题意:有n个房子,这些房子被n-1条道路连接,有一些运动员从一个房子为起点尽可能跑最远的距离且不能通过一条道路超过两次,这些运行员不能选择同样的起点,这些运动员跑的最远距离和最近距离的差值不能超过Q, ...
- oracle 密码忘记、密码遗失解决办法
忘了密码可以用操作系统验证方式登入SYS用,然后可以随意修改密码了.登入方法:1.进入命令提示符下,输入:sqlplus /nolog 回车进入SQL.2.在SQL环境下,输入:SQL> con ...