当前位置:网站首页>Knapsack model acwing 423. Picking herbs
Knapsack model acwing 423. Picking herbs
2022-07-27 11:13:00 【T_ Y_ F666】
Backpack model AcWing 423. collect Chinese medicinal herbs
Original link
AcWing 423. collect Chinese medicinal herbs
Algorithm tags
DP 01 knapsack problem
Ideas
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 1005;
// f[i] The storage time is i when , The maximum total value of the collected herbs .
int f[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=read(), m=read();
int ans=0;
rep(i, 0, m){
int tt=read(), v=read();
Rep(j, t, tt){
f[j]=max(f[j], f[j-tt]+v);
}
}
printf("%lld", f[t]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
猜你喜欢

What is the mystery of the gate of the meta universe?

A verification test of the relationship between iteration number and entropy

NFT leaderboard -nft real offer latest address: NFT leaderboard.com

Wilderness search --- search iterations

解决 ImportError: cannot import name 'abs' 导入tensorflow报错

Kangaroo cloud stack based on CBO in spark SQL optimization

推导STO双中心动能积分的详细展开式

背包模型 AcWing 423. 采药

Symmetric encryption and asymmetric encryption

Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
随机推荐
树形数据转换
15th largest value of data flow
Symmetric encryption and asymmetric encryption
15 design movie rental system
SQL Server2000数据库错误
C语言 2:求三数字最大值,求三数字中间值,编写程序步骤
Play with the cluster configuration center and learn about the Taier console
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
基于FPGA的ECG信号采集,存储以及传输系统verilog实现
IO流_字符流、IO流小结、IO流案例总结
Students, don't copy all my code, remember to change it, or we both want G
Overview of data security in fog computing
The difference of iteration number and information entropy
Thank you for your likes and attention
c语言指针函数和函数指针的辨析
Time and power allocation method to ensure fairness in sensor fusion system
最长上升子序列模型 AcWing 1012. 友好城市
洛谷P1896 互不侵犯
背包模型 AcWing 1022. 宠物小精灵之收服
Analysis of new communication security risks brought by quantum computer and Countermeasures