分组背包
  • 板块学术版
  • 楼主Surge_of_Force
  • 当前回复5
  • 已保存回复5
  • 发布时间2021/8/3 09:43
  • 上次更新2023/11/4 12:10:29
查看原帖
分组背包
230875
Surge_of_Force楼主2021/8/3 09:43

这个分组背包有什么问题吗

#include<bits/stdc++.h>
using namespace std;
int w[15][35],c[15][35],f[210],xh[15];
int main()
{
	int v,n,t;
	cin>>v>>n>>t;
	for(int i=1;i<=n;i++)
	{
		int x,y,p;
		cin>>x>>y>>p;
		w[p][++xh[p]]=x;
		c[p][++xh[p]]=y;
	}
	for(int i=1;i<=t;i++)
	    for(int k=v;k>=0;k--)
		    for(int j=1;j<=xh[i];j++)
		        if(k>=w[i][j])
	            f[k]=max(f[k],f[k-w[i][j]]+c[i][j]);
	cout<<f[v];
	return 0;
}

2021/8/3 09:43
加载中...