当前位置:网站首页>P1048 [NOIP2005 普及组 T3] 采药
P1048 [NOIP2005 普及组 T3] 采药
2022-07-25 07:36:00 【hnjzsyjyj】
【题目描述】
https://www.luogu.com.cn/problem/P1048
https://www.acwing.com/problem/content/description/425/
【题目描述】
辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师。
为此,他想拜附近最有威望的医师为师。
医师为了判断他的资质,给他出了一个难题。
医师把他带到一个到处都是草药的山洞里对他说:“孩子,这个山洞里有一些不同的草药,采每一株都需要一些时间,每一株也有它自身的价值。我会给你一段时间,在这段时间里,你可以采到一些草药。如果你是一个聪明的孩子,你应该可以让采到的草药的总价值最大。”
如果你是辰辰,你能完成这个任务吗?
【输入格式】
输入文件的第一行有两个整数 T 和 M,用一个空格隔开,T 代表总共能够用来采药的时间,M 代表山洞里的草药的数目。
接下来的 M 行每行包括两个在 1 到 100 之间(包括 1 和 100)的整数,分别表示采摘某株草药的时间和这株草药的价值。
【输出格式】
输出文件包括一行,这一行只包含一个整数,表示在规定的时间内,可以采到的草药的最大总价值。
【数据范围】
1≤T≤1000,1≤M≤100
【算法分析】
● 闫氏DP分析法:https://www.bilibili.com/video/BV1X741127ZM
●* 最后一步法:https://www.bilibili.com/video/BV1xb411e7ww
【算法代码】
#include <bits/stdc++.h>
using namespace std;
const int maxn=1005;
int t,m;
int f[maxn];
int main(){
cin>>t>>m;
for(int i=0;i<m;i++){
int w,val;
cin>>w>>val;
for(int j=t;j>=w;j--)
f[j]=max(f[j],f[j-w]+val);
}
cout<<f[t]<<endl;
return 0;
}
/*
in:
70 3
71 100
69 1
1 2
out:
3
*/
【参考文献】
https://www.bilibili.com/video/BV1X741127ZM
https://www.bilibili.com/video/BV1oL4y187Fq
https://www.bilibili.com/video/BV1xb411e7ww
https://www.acwing.com/solution/content/6272/
边栏推荐
- 3. Promise
- [unity introduction program] basic concepts -2d rigid body 2D
- "Game illustrated book": a memoir dedicated to game players
- On the peak night of the 8 Oracle ace gathering, what technology hotspots did you talk about?
- Growth path - InfoQ video experience notes [easy to understand]
- 【Unity入门计划】基本概念-2D刚体Rigidbody 2D
- 【Unity入门计划】基本概念-2D碰撞体Collider 2D
- 【程序员2公务员】关于体制调研的一些常见问题总结
- 【微信小程序】全局样式、局部样式、全局配置
- 使用CycleGAN训练自己制作的数据集,通俗教程,快速上手
猜你喜欢

【论文笔记】EFFICIENT CNN ARCHITECTURE DESIGN GUIDED BY VISUALIZATION

一日千里,追风逐月 | 深势科技发布极致加速版分子对接引擎Uni-Docking

What has become a difficult problem for most people to change careers, so why do many people study software testing?
![[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x](/img/7e/1d27e3f1856ab8c6cbfc5221c717bb.png)
[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x

A fast method of data set enhancement for deep learning

Before Oracle 19C migration, how important is it to do a good job of rat playback test?
![[unity entry plan] interface Introduction (1) -scene view](/img/88/dee292cb90cd740640018e7260107f.png)
[unity entry plan] interface Introduction (1) -scene view

【Unity入门计划】制作我的第一个小游戏

曼哈顿距离简介

Polling, interrupt, DMA and channel
随机推荐
The application of for loop and if judgment statement
全新8.6版本SEO快排系统(可源码级搭建)
如何在KVM环境中使用网络安装部署多台虚拟服务器
华为无线设备配置WAPI-证书安全策略
Leetcode skimming: dynamic programming 06 (integer splitting)
曼哈顿距离简介
list的模拟实现
9大最佳工程施工项目管理系统
使用CycleGAN训练自己制作的数据集,通俗教程,快速上手
How to use kotlin flow in Android projects
[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x
【Unity入门计划】界面介绍(1)-Scene视图
Lidar construction map (overlay grid construction map)
for循环与if判断语句的运用
Offline base tile, which can be used for cesium loading
Flinkcdc2.0 uses flinksql to collect MySQL
2-6.自动化采集
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (V)
When providing digital talent services, Xi Zhi quickly opened its own digital school for each organization
钉钉最新版,怎么清除登录手机号历史记录数据