hdu 1300 Pearls(dp)

很好用的离线版杭电OJ 这个版本包含了杭电水题里面的全部题目,内容丰富,可以供你在没有网络的时候观看题目,好好用哦. 立即下载

Pearls

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


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

 

思路:dp[x]表示前x种类别的最优值,

           dp[x]=min(dp[j]+(num[i][j]+10)*pri[j]);(1<=i<=j<=x)

很蛋疼的地方,这一神一样让我TLE了3次,就因为我用了个while(cin>>cas)

给大家看看。

AC代码

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int mm=1010;
const int oo=1e9;
int cas;
class node
{
    public:
    int num,pri;
}f[mm];
int dp[mm];
int n;
int main()
{
        cin>>cas;
        for(int zz=0;zz<cas;zz++)
        {
          cin>>n;
          for(int i=1;i<=n;i++)
          {
              cin>>f[i].num>>f[i].pri;
          }
          dp[0]=0;
          dp[1]=(f[1].num+10)*f[1].pri;
          for(int i=2;i<=n;i++)
          {  int _min=oo;
            for(int j=1;j<=i;j++)///枚举每种情况
            {  int sum,num=f[j].num;
              for(int k=j+1;k<=i;k++)
               num+=f[k].num;
               sum=(num+10)*f[i].pri+dp[j-1];
               if(sum<_min)_min=sum;
            }
            dp[i]=_min;
          }
          cout<<dp[n]<<"\n";
        }
    
}


TLE代码

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int mm=1010;
const int oo=1e9;
int cas;
class node
{
    public:
    int num,pri;
}f[mm];
int dp[mm];
int n;
int main()
{
    while(cin>>cas)
    {
        for(int zz=0;zz<cas;zz++)
        {
          cin>>n;
          for(int i=1;i<=n;i++)
          {
              cin>>f[i].num>>f[i].pri;
          }
          dp[0]=0;
          dp[1]=(f[1].num+10)*f[1].pri;
          for(int i=2;i<=n;i++)
          {  int _min=oo;
            for(int j=1;j<=i;j++)///枚举每种情况
            {  int sum,num=f[j].num;
              for(int k=j+1;k<=i;k++)
               num+=f[k].num;
               sum=(num+10)*f[i].pri+dp[j-1];
               if(sum<_min)_min=sum;
            }
            dp[i]=_min;
          }
          cout<<dp[n]<<"\n";
        }
    }
}


 

 

 

LoFTR训练避坑指南:从零到一复现论文训练流程 本文是一份详细的LoFTR模型训练避坑指南,旨在帮助开发者从零开始复现论文训练流程。文章系统性地讲解了环境配置、数据准备、代码调试与显存优化等关键步骤,并针对常见的训练错误提供了解决方案,确保训练过程顺利进行。 阅读详情

相关推荐

别再自己写组件了!用uni-app的midButton属性5分钟搞定中间凸起TabBar(H5/小程序通用)

本文详细介绍了uni-app官方提供的midButton属性,帮助开发者5分钟内实现中间凸起的TabBar效果,无需编写繁琐的自定义组件代码。该方案兼容H5和微信小程序平台,配置简单且维护成本低,大幅提升开发效率和性能表现。

weixin_30431445的博客 347

E - Pearls(dp)

题目描述: 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 o...

年轻过成了秃顶 333

从零到一:Livox Mid-360 激光雷达的硬件集成与避坑实战

本文详细介绍了Livox Mid-360激光雷达的硬件集成全流程,包括硬件准备、网络配置、驱动编译和常见问题解决方案。通过实战经验,帮助开发者高效完成从设备拆箱到数据输出的完整链路,避免在IP设置、驱动编译和固件兼容性等环节踩坑。

salt的博客 1030

POJ 1260-Pearls 动态规划

<br />题目来源:http://124.205.79.250/JudgeOnline/problem?id=1260<br /> <br />解题报告:<br /> <br />一开始觉得可以用贪心算法,后来发现是不对的,比方说对如下的测试数据:<br />10 10<br />5  15<br />10 23<br />就不行了。还是要用动态规划来解<br /> <br />我设f[k]代表只买前k个,可以花的最少的钱。<br />则<br />f[k]=min( (a1+a2+...+ak+10)*

kindlucy的专栏 2282

倾向得分匹配的stata命令_政策评估方法引荐|广义倾向得分匹配(GPSM)

和大家分享一下最近学习的进展,在痛苦读完stata journal和练习OA程序,已经可以基本完成广义倾向得分的估计了,在国内这一方法还没有形成广泛运用,因此学习资源也是有点稀缺的,在文章最后给各位提供数据和代码以供练习。有问题可以随时文末留言或者联系我哦。人文社会科学中一般无法在实验室中控制样本个体的特征,我们一般采用“准自然实验”的研究路径,也就是不随机安排样本接受处理与否。但放弃随机分组假定...

weixin_39550258的博客 1万+

【Spring源码三千问】哪些循环依赖问题Spring解决不了?

哪些循环依赖问题Spring解决不了?前言版本约定正文场景一: prototype 类型的循环依赖场景二: constructor 注入的循环依赖场景三:Proxy 类型的 Bean 的循环依赖小结 系列博文: 【老王读Spring IoC-0】Spring IoC 引入 【老王读Spring IoC-1】IoC 之控制反转引入 【老王读Spring IoC-2】IoC 之 BeanDefinition 扫描注册 【老王读Spring IoC-3】Spring bean 的创建过程 【老王读Spring I

老王的专栏 7319

pearal.

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

nearal的博客 335

告别臃肿VS!仅用Visual Studio 2022 Build Tools为Qt 5.12.12配置MSVC2017开发环境

本文详细介绍了如何仅使用Visual Studio 2022 Build Tools为Qt 5.12.12配置MSVC2017开发环境,避免安装臃肿的完整VS。通过精准选择组件、配置Qt Creator编译器和优化Kit设置,实现高效、精简的Windows平台Qt开发环境搭建,特别适合追求性能和资源优化的开发者。

weixin_30340617的博客 350

HDU 1300 Pearls 斜率DP 入门

HDU 1300 Pearls 给 ccc 个种类的珍珠,每个有需要的数量以及对应的价格,购买某种类时需要额外再加十个,可以通过购买高种类的来替代低种类的。 可以得到状态转移方程: dp[i]=min⁡{dp[k]+p[i]×(s[i]−s[k]+10)},k∈[1,i−1] dp[i]=\min\{dp[k]+p[i]\times(s[i]-s[k]+10)\}, k\in [1,i-1] dp...

wineandchord 253

Mplus—随机截距交叉滞后模型(RI-CLPM)语法

随机截距交叉滞后模型RI-CLPM的Mplus语法。

m0_54401011的博客 2532

5.30华为OD机试真题 新系统 - 链表数字游戏 (Java/Py/C/C++/Js/Go)

5.30华为OD机试真题 新系统 - 链表数字游戏 (Java/Py/C/C++/Js/Go)

算法大师! 1121

HDU-1300(基础方程DP-遍历之前所有状态)

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...

weixin_34293902的博客 180

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

hdu 1300 Pearls dp

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1300 简单dp 两种状态  单独买 或者j ~ i 合起来买   #include&lt;bits/stdc++.h&gt; using namespace std; #define ll long long int const int INF = 0x3f3f3f3f; const in...

甦萌的博客 207

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HDU 1300 Pearls(DP)

题意  珠宝店到珍珠批发商进货  第i种价格为p[i]的珍珠需要n个  则珍珠的结算价格为∑(n+10)*p[i]   由于没种珍珠的数量结算时都要加上10   所以有时候把便宜的珍珠换为贵的结算价格反而变少了   给你一张购买清单   珍珠价格是递增的   每种珍珠都可以替换为比它贵的  求最少总花费 简单dp  令d[i]表示前i种珍珠的最少花费  sum[i]表示第1种到第第i种的总数  

Good morning,good afternoon and good night 1204

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

[HDU 1300]Pearls[DP]

题目链接:[HDU 1300]Pearls[DP] 题意分析: 总共有C种等级的珍珠,每种需要买a[i]个,单个价格为p[i]元,如果想要买某种等级的珍珠,需要先交付10个该等级珍珠的价格才能进行购买,允许使用高等级珍珠替换需要买的低等级珍珠。问:要达到采购需求,最少需要花费多少的经费?(等级越高,单价越高:) 解题思路: 设dp[i]代表到第i种等级的珍珠,需要花费的最少费用。那么初始化

闲停 679

HDU1300 Pearls —— 斜率优化DP

题目链接:https://vjudge.net/problem/HDU-1300 Pearls Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2920Accepted Submission(s): 1464 ...

alince20008的博客 191

hdu1300 Pearls 【dp】

没有看到限制条件,品质越高的价格就越贵,导致想了一个多月都写不出来。#include<bits/stdc++.h> using namespace std; int a[1024],p[1024],dp[1024],sum[1024];int main() { int _,n; scanf("%d",&_); while(_--) { scanf("%

禅境花园 543

HDU1300 Pearls(dp)

Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3375    Accepted Submission(s): 1685 Problem Description In Pearlania everybody is fo...

BBHHTT的博客 364

【DP】HDU-1300 Pearls

给出n种珠宝,每种价格不同,有一定的需求量。若要购买某种珠宝,必须先付10单位的该珠宝价格。按珠宝价格从小到大输入。可以用更高价格的珠宝来代替低价格的珠宝,但是反之不行。问最后的最小花费。

JSure的代码库 873

HDU 1300 Pearls--dp

题意:有不同等级的珍珠,价格不同,现在列出需要买的珍珠,求花的最少的钱(可以买高等级的来代替低等级的) 分析:dp[i]表示从最低等级到 i 等级花的最少的钱,dp[i]=min(dp[j]+v) v是从j+1到i全买i等级花的钱。需要三重循环。 代码: #include #include #include #define INF 1000000007 using namespace std

关于学习本身 776

HDU 1300 Pearls DP .

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1300 就是要明白 一些东西的的数量的累加肯定是连续的 比如 不可能a2累加到a4,跳过a3,而应该是a2,a3 都累加到a4 #include #include #include #include using namespace std; const int maxn=200+5; con

BRCOCOLI的博客 372

HDU - 1300 Pearls (dp)

Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2666    Accepted Submission(s): 1316 Problem Description In Pearlania everyb

HHH_go_的博客 1068

HDU 1300 Pearls (DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1300 题目大意:珠宝店有100种不同质量的珍珠,质量越高价钱越高,为了促进销售,每买一种类型的珍珠,要在原来的基础上必须再买10个。这时一个CFO发现,这种条件下,有时买质量更好的反而更便宜。比如要买10元的珍珠5个,20元的珍珠100个,普通的买法需要(5+10)*10 + (100+10)*20...

weixin_30565327的博客 81

HDU 1300 Pearls (dp)

【题目链接】 http://acm.hdu.edu.cn/showproblem.php?pid=1300 题目意思 皇家要购买一些珍珠,但是珍珠品质不一样,把不同品质珍珠分为1到100个等级,买没个等级的珍珠需要的支付的钱是:(数量+10)乘上单价。而皇室当然不介意买的的珍珠比要求的高级(也就是高等级珍珠可以代替低等级珍珠)现在已知皇室需要的珍珠清单,问你所需的最低价格。 解题思...

绝丶爵的博客 211

hdu 1300 Pearls DP

方程很好推,n^2过的。 #include #include #include using namespace std; #define maxn 105 int a[maxn],p[maxn],sum[maxn]; int dp[maxn]; int main() { int t,n; scanf("%d",&t); while(t--) { s

793
上一篇: hdu 1227 Fast Food(DP线性决策)
下一篇: hdu 2993 MAX Average Problem(DP+斜率优化)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值