hdu 1300 Pearls(dp)

Revit二次开发之获取钢筋(Rebar)的线(Line) 这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar 阅读详情

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";
        }
    }
}


 

 

 

用 SAP-ABAP-1 把 ABAP 代码读懂:从 Generative AI Hub Orchestration 到 Joule 落地的实战指南 SAP-ABAP-1 是 SAP 推出的 ABAP 专用基础模型,专注于代码解释与理解。它能显著降低企业遗留系统的维护成本,帮助开发人员快速掌握复杂业务逻辑。该模型通过 SAP Generative AI hub 托管,支持 128,000 tokens 的上下文长度,适合分析大型 ABAP 类和 CDS 视图。典型应用场景包括代码解释、迁移辅助和云合规检查。调用需通过 Orchestration service 进行,确保企业级安全治理。 阅读详情

相关推荐

ArcGIS | 全球新冠肺炎地图数据下载和处理

ArcGIS

thinkpang的博客 2906

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

联想Y9000P安装Ubuntu20.04记录

联想Y9000P 2022安装Ubuntu20.04问题记录

Legendyyy的博客 7131

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

PADS Layout差分对布线实战:从规则设置到高速信号优化

本文详细讲解了在PADS Layout中进行差分对布线的完整实战流程。从在Layout中定义差分对网络,到进入Router配置线宽、间距等关键规则,再到布线实战技巧与高速信号完整性优化,系统阐述了如何确保差分信号(如USB、HDMI)的稳定传输,是高速PCB设计的核心技能。

weixin_29274969的博客 529

ENVI 5.6保姆级教程:高分七号DLC影像从打开到融合的完整流程(附避坑指南)

本文详细介绍了ENVI 5.6处理高分七号DLC影像的完整流程,包括环境准备、数据解压、正射校正、图像融合等关键步骤。特别针对国产卫星数据处理的独特挑战,提供了实用的避坑指南和优化技巧,帮助用户高效完成光学影像的预处理和质量提升。

weixin_33269743的博客 388

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

手把手教你用SysMax桥接软件搞定CANoe、INCA和刷写工具(附驱动配置避坑点)

本文详细介绍了如何使用SysMax PCAN FD桥接软件实现CANoe、INCA和刷写工具的无缝对接,提供从驱动配置到多软件协同的全链路指南。重点解析了驱动安装避坑点、CANoe配置技巧、INCA集成方法以及刷写工具链优化方案,帮助汽车电子工程师构建高效开发环境。

weixin_30500105的博客 394

HDU_1300 Pearls 【DP】

题目链接 题目描述 一道特别长的英文题目,其实就是让你算一下怎么用最少的钱把这所有的珍珠给买下来。题目上给出n种珍珠,每种珍珠对应着数量和价格(价格从小到大排列)。你有两种购买方式:1.一次只买一种,但是需要你多买10个 2.可以连续着买多种,最后也需要多买10个,所有的珍珠都需按照价格最高的来计算(可以从任意位置开始连续,可以有多个连续)。 解题思路 首先我们用一个dp[i]数组,

Learning Deep Learning 288

YOLOv5+Astra Pro Plus深度相机:手把手教你实现实时目标检测(附ROS配置技巧)

本文详细介绍了如何将YOLOv5目标检测算法与Astra Pro Plus深度相机结合,构建实时目标检测系统。内容涵盖从硬件选型、环境搭建、ROS配置到YOLOv5部署与深度信息融合的完整流程,并分享了性能优化、避障算法等实战技巧,帮助开发者在机器人视觉等场景中快速实现智能感知应用。

weixin_28292761的博客 399

【GameFramework框架内置模块】15、场景(Scene)

场景(Scene)模块,提供场景管理的功能,负责场景的加载、卸载、切换和管理。可以方便地管理不同场景之间的切换以及不同场景之间的信息传递。

CSDN博客专家,Unity3D高级软件工程师,《Unity 3D从入门到实战》作者。 1890

hdu1300(水题也是dp)

这题dp的很巧妙,反正这个题目题意我是没弄清楚,讲的不好。状态方程 dp[i] = max { dp[j-1] + (sum[i] - sum[j-1])*p[i] }  (选择某段进行替换) #include #include #include #include #include #include #include #include using namespace std; typedef

ACM之梦 790

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

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

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

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

甦萌的博客 208

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

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

[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的博客 192

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的博客 366

【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、付费专栏及课程。

余额充值