当前位置:网站首页>Luogu - p1616 crazy herb picking
Luogu - p1616 crazy herb picking
2022-07-24 20:09:00 【xyc20120615】
Background
The title is to commemorate LiYuxiang born .
Title Description
LiYuxiang He is a gifted child , His dream is to become the greatest doctor in the world . So , He wants to learn from the most prestigious doctor in the neighborhood . In order to judge his qualifications , Gave him a problem . The doctor took him to a cave full of herbs and said :“ children , There are some different kinds of herbs in this cave , It takes some time to pick each , Each has its own value . I'll give you a period of time , In the meantime , You can pick some herbs . If you are a smart kid , You should be able to maximize the total value of the herbs you pick .”
If you are LiYuxiang, Can you finish the task ?
The difference between this question and picking herbs :
1. Every herb can be picked without limit .
2. The variety of medicine is dazzling , It's a long time to collect medicine ! Master, thank you for waiting !
Input format
The first line of input has two integers , Each represents the total time that can be used to collect medicine t And the number of herbs in the cave m.
The first 2 To the first (m+1) That's ok , Two integers per line , The first (i+1) The whole number of lines ai,bi They represent the second day of picking ii The time to plant the herb and the value of the herb .
Output format
Output one line , This line contains only one integer , Within a specified time , The maximum total value of herbs available .
I/o sample
Input #1
70 3
71 100
69 1
1 2Output #1
140explain / Tips
Data scale and agreement
- about 30% The data of , Guarantee m≤10^3 .
- about 100% The data of , Guarantee 1≤m≤10^4,1≤t≤10^7, And 1≤m×t≤10^7,1≤ai,bi≤10^4.
Answer key :
It's a complete knapsack problem , The only one ( This is not a dash , It's two ones ) The point to note is that the data range will become long long, Or it will explode 90. Have to say ,lg The previous data really H2O
Program :
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[10010],b[10010],dp[10000010];
int main(){
cin>>m>>n;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i];
for(int i=1;i<=n;i++)
for(int j=a[i];j<=m;j++)
dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
cout<<dp[m];
return 0;
}边栏推荐
- 2019 Hangzhou Electric Multi School Game 9 6684 Rikka with game [game question]
- Are network security and data security indistinguishable? Why is data security important?
- [German flavor] safety: how to provide more protection for pedestrians
- Student achievement management system based on PHP
- Decorator of function
- 02 | environment preparation: how to install and configure a basic PHP development environment under windows?
- Ask a question: is there an error msg = ora-04036: instance usage when using CDC to monitor oracle
- Wechat applet -that.setdata ({}) set complex field data
- Wechat stores build order pages and automatically grab tickets
- Solutions to oom caused by pictures in res directory
猜你喜欢

Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)

Virtual machine win7 system installation vmtool

Google's display of Chrome browser icons was abandoned, and it was intended to be a small rocket

Introduction to WDK development 1- basic environment construction and the first driver (VS2010)

The ark compiler is coming. What about APK reinforcement
![[leetcode] 1184. Distance between bus stops](/img/8c/c396e6f614f465bc09b0653540a1c8.png)
[leetcode] 1184. Distance between bus stops

从服务器批量下载文件到本地

Maya coffee machine modeling

Lunch break train & problem thinking: on multidimensional array statistics of the number of elements

聊下自己转型测试开发的历程
随机推荐
Inconsistent time
Connect the smart WiFi remote control in the home assistant
English translation Chinese common dirty words
Unity2d~ game practice of decrypting Zhou mu (completed in three days)
Make Huawei router into FTP server (realize upload and download function)
微服务架构 | 服务监控与隔离 - [Sentinel] TBC...
Rotation matrix derivation process
strlen函数剖析和模拟实现
Sql164 next day retention rate of new users per day in November 2021
How to export map files tutorial
MySQL advanced
870. Approximate number
Redis common configuration description
[face to face experience of school recruitment] 8 real questions of pointer interview. Come and test how many you have mastered.
Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
ATL container - catlmap, crbmap
BGP - border gateway protocol
Unit DLU of resource editor
Review the code implementation of memcpy function
Use of paging assistant PageHelper