当前位置:网站首页>分组背包呀
分组背包呀
2022-04-23 07:21:00 【2020100XWH】
所有物品分成k组,组内互斥
对组01背包,最后一维枚举组中哪个
#include<bits/stdc++.h>
using namespace std;
int dp[1005];
struct one{
int m,w;
};
vector <one> v[1005];
int main()
{
int n,m;
cin>>m>>n;
int a,b,c;
for(int i=1;i<=n;++i)
{
cin>>a>>b>>c;
v[c].push_back((one){a,b});
}
for(int i=1;i<=1000;++i)
{
if(v[i].size())
{
for(int j=m;j>=0;--j)
{
for(int k=0;k<v[i].size();++k)
{
if(j>=v[i][k].m)
dp[j]=max(dp[j],dp[j-v[i][k].m]+v[i][k].w);
}
}
}
}
cout<<dp[m];
return 0;
}
版权声明
本文为[2020100XWH]所创,转载请带上原文链接,感谢
https://blog.csdn.net/xuwnehao/article/details/124351809
边栏推荐
- php生成短链接:将数字转成字母,将字母转成数字
- WordPress love navigation theme 1.1.3 simple atmosphere website navigation source code website navigation source code
- Why are there 1px problems? How?
- Flatten arrays
- An idea plug-in that doesn't work, but can install X
- A simple theme of Typecho with beautiful appearance_ Scarfskin source code download
- Online yaml to XML tool
- 单点登录 SSO
- Jetson Xavier NX (3) bazel mediapipe installation
- Multi vision slam
猜你喜欢

vslam PPT

Talk about the basic but not simple stock data
![[learning] audio and video development from scratch (9) -- nuplayer](/img/62/20b0d80088181fb6ff1fe842500c0a.png)
[learning] audio and video development from scratch (9) -- nuplayer
![[untitled]](/img/bb/213d95b60651dfeadb239a70507506.png)
[untitled]

每周leetcode - 06 数组专题 7~739~50~offer 62~26~189~9

Vowel substring in statistical string of leetcode simple problem

谈谈那些基础但不简单的股票数据

【解释】get ORA-12838: cannot read/modify an object after modifying it in parallel

LeetCode简单题之重新排列日志文件

Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
随机推荐
There are some problems when using numeric type to query string type fields in MySQL
C language learning record -- use and analysis of string function (2)
Brief description of CPU
5.6 comprehensive case - RTU-
AQS & ReentrantLock 实现原理
3C裝配中的機械臂運動規劃
nn.Module类的讲解
My heart's broken! A woman's circle of friends envied others for paying wages on time and was fired. Even her colleagues who liked her were fired together
Implementation of promise all
JS common array methods
浅谈ES6尾调优化
ApplicationReadyEvent的使用
Interesting JS code
How to read books and papers
Thinkphp6 + JWT realizes login verification
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
微信小程序 catchtap=“toDetail“ 事件问题
一篇文章看懂变量提升(hoisting)
The third divisor of leetcode simple question
WordPress爱导航主题 1.1.3 简约大气网站导航源码网址导航源码