c++ 二维背包dp
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int n,V, M;
int f[N][N];
int main(){
cin>>n>>V>>M;
// 二维约束背包问题
for(int i=0; i<n; ++i){
int v, m, w;
cin>>v>>m>>w;
for(int j=V; j>=v; --j)
for(int k=M; k>=m; --k)
f[j][k]=max(f[j][k], f[j-v][k-m]+w);
}
cout<<f[V][M]<<endl;
return 0;
}
python 二维背包dp
class Solution:
def main(self, n:int, V:int , M:int):
f = [[0 for _ in range(M+1)] for _ in range(V+1)]
for i in range(n):
v,m,w=map(int, input().split())
for j in range(v, V+1)[::-1]:
for k in range(m, M+1)[::-1]:
f[j][k]=max(f[j][k], f[j-v][k-m]+w)
return f[V][M]
if __name__ == '__main__':
n,V,M=map(int, input().split())
sol=Solution()
print(sol.main(n, V, M))