当前位置:网站首页>分组背包呀
分组背包呀
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
边栏推荐
- Install MySQL for Ubuntu and query the average score
- 2022.4.11-4.17 AI industry weekly (issue 93): the dilemma of AI industry
- [go] common concurrency model [generic version]
- Brief description of CPU
- Transformer-XL: Attentive Language ModelsBeyond a Fixed-Length Context 论文总结
- [learning] audio and video development from scratch (9) -- nuplayer
- Online yaml to XML tool
- 浅谈ES6尾调优化
- C language learning record -- use and analysis of string function (2)
- WordPress爱导航主题 1.1.3 简约大气网站导航源码网址导航源码
猜你喜欢

PyQt5开发之QTableWidget表头自定义与美化(附源代码下载)

A simple theme of Typecho with beautiful appearance_ Scarfskin source code download

LeetCode简单题之三除数

The simple problem of leetcode is to calculate the numerical sum of strings

Search the complete navigation program source code

【无标题】

校园转转二手市场源码下载

mysql查询字符串类型的字段使用数字类型查询时问题

LeetCode简单题之计算字符串的数字和

Talk about the basic but not simple stock data
随机推荐
js常用数组方法
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
An idea plug-in that doesn't work, but can install X
Comparison of indoor positioning technology
【Appium】测试时遇到手机内嵌H5页面的切换问题
【无标题】
2022.4.11-4.17 AI行业周刊(第93期):AI行业的困局
LeetCode简单题之统计字符串中的元音子字符串
Fibula dynamic programming
Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
How to import Excel data in SQL server, 2019 Edition
thinkphp6+jwt 实现登录验证
A simple theme of Typecho with beautiful appearance_ Scarfskin source code download
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
PHP generates short links: convert numbers to letters and letters to numbers
Positioning of high precision welding manipulator
PHP high precision computing
2022.4.11-4.17 AI industry weekly (issue 93): the dilemma of AI industry
一篇文章看懂变量提升(hoisting)
Thinkphp6 + JWT realizes login verification