当前位置:网站首页>分组背包呀
分组背包呀
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
边栏推荐
猜你喜欢
随机推荐
[effective go Chinese translation] part I
AAAI 2022招募讲者啦!!
Brief description of CPU
[Effective Go 中文翻译]函数篇
基于TCP/IP协议的网络通信实例——文件传输
Ubuntu安装Mysql并查询平均成绩
Why are there 1px problems? How?
Discussion on ES6 tail tune optimization
Compiler des questions de principe - avec des réponses
PHP generates short links: convert numbers to letters and letters to numbers
LeetCode15. Sum of three
nn.Module类的讲解
Compiling principle questions - with answers
有意思的js 代码
Positioning of high precision welding manipulator
DataBinding的使用五
Listed on the Shenzhen Stock Exchange: the market value is 5.2 billion yuan. Lu is the East and his daughter is American
怎么读书读论文
Multi vision slam
【无标题】