Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
143517 陈家宝 分组背包 C++ 通过 100 2 MS 1064 KB 538 2024-04-16 16:17:20

Tests(15/15):


#include<bits/stdc++.h> using namespace std; int m,n,p,K,w[10001],c[10001],f[10001],stone[10001][1001]; int main(){ cin>>m>>n; for(int i=1; i<=n; i++){ cin>>w[i]>>c[i]>>p; stone[p][++stone[p][0]]=i; K=max(K,p);//统计最多有多少组 } for(int k=1;k<=K;k++)for(int j=m;j>=0;j--)for(int i=1;i<=stone[k][0];i++)if(w[stone[k][i]]<=j)f[j]=max(f[j],f[j-w[stone[k][i]]]+c[stone[k][i]]);//枚举组数|倒序枚举背包容量|枚举k组里的所有物品|如果可以放 cout<<f[m]; return 0; }


测评信息: