题目描述
blablabla
样例
import java.util.Scanner;
public class Main {
static int N = 1010;
static int n,V,M;
static int[] v ;
static int[] m ;
static int[] w ;
static int[][][] f ;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n=scanner.nextInt();
V=scanner.nextInt();
M=scanner.nextInt();
v = new int[N];
m = new int[N];
w = new int[N];
f= new int[N][110][110];
for (int i = 1; i <= n; i++) {
v[i] = scanner.nextInt();
m[i] = scanner.nextInt();
w[i] = scanner.nextInt();
}
for (int i = n; i >=1 ; i--) {
for (int j = 0; j <= V; j++) {
for (int k = 0; k <= M; k++) {
if (j< v [i] || k < m[i] ){
f[i][j][k] = f[i+1][j][k];
}else {
f[i][j][k] = Math.max(f[i+1][j][k],f[i+1][j-v[i]][k-m[i]]+w[i]);
}
}
}
}
System.out.println(f[1][V][M]);
}
}
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla