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的平均值,两边平方得 平均 ...
随机推荐
- NPOI 导入,导出EXCEL
代码: public static class NPOIExcelHelper { /// <summary> /// DataTable导出到Excel文件 /// </summa ...
- 安装ECshop普遍问题的解决方法
安装ecshop经常会出现以下问题: 1.Strict Standards: Non-static method cls_image::gd_version() should not be calle ...
- Java定时任务Timer、TimerTask与ScheduledThreadPoolExecutor详解
定时任务就是在指定时间执行程序,或周期性执行计划任务.Java中实现定时任务的方法有很多,本文从从JDK自带的一些方法来实现定时任务的需求. 一.Timer和TimerTask Timer和Tim ...
- nexenta systemcallerror
最近在试nexenta做iscsi,设置ip出现上面的错误 解决办法,先讲mtu设置为不周与原来的值,比如原来为1500,先设置成1501,就可以了,然后可以再改回来,也是没有问题的!
- "淘宝推荐系统简介"分享总结
概述: 此分享是关于淘宝推荐系统简介 1.推荐引擎就是:如何找到用户感兴趣的东西和以什么形式告诉用户:2.推荐引擎的作用:提高用户忠诚度,提高成交转化率和提高网站交叉销售能力:3.推荐系统核心:产品, ...
- Custom IFormatProvider
The following example shows how to write a custom IFormatProvider which you can use in methodString. ...
- redhat linux 安装mysql5.6.27
1.yum安装mysql(root身份) yum install mysql-server mysql-devel mysql -y 如没有配置yum,请参见博客:http://www.cnblogs ...
- <s:iterator> 对list操作的一种方法
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA6IAAAH3CAIAAAAuRnW9AAAgAElEQVR4nOzdf4gk1333+wLDDffhPp
- collection和collections区别
collection和collections区别 collection-->是集合类的上级接口,继承他的接口主要有set,list collections-->是针对集合类的一个帮助类,提 ...
- yii框架中保存第三方登录信息
(第三方登录) 创建应用,域名,详情请看:http://www.cnblogs.com/xujn/p/5287157.html 效果图: