update at 2022-03-24 09:32:13 by ehlxr

master
ehlxr 2022-03-24 09:32:13 +08:00
parent b7da6e9537
commit aaccb2114b
1 changed files with 21 additions and 3 deletions

View File

@ -30,20 +30,38 @@ package io.github.ehlxr.algorithm.dp;
* @author ehlxr
* @since 2022-03-05 14:31.
*/
public class KnapSack3 {
public class KnapSack {
private final int[] weight = {2, 2, 4, 6, 3}; // 物品的重量
private final int[] value = {3, 4, 8, 9, 6}; // 物品的价值
private final int n = 5; // 物品个数
private final int w = 9; // 背包承受的最大重量
private int maxV = Integer.MIN_VALUE; // 结果放到 maxV 中
public static void main(String[] args) {
System.out.println(knapsack3(new int[]{2, 2, 4, 6, 3}, new int[]{3, 4, 8, 9, 6}, 5, 9));
System.out.println(knapsack(new int[]{2, 2, 4, 6, 3}, new int[]{3, 4, 8, 9, 6}, 5, 9));
}
/**
*
*
* @param weight
* @param value
* @param n:
* @param w:
* @param n
* @param w
* @return
*/
public static int knapsack(int[] weight, int[] value, int n, int w) {
int[][] dp = new int[][];
}
/**
*
*
* @param weight
* @param value
* @param n
* @param w
* @return
*/
public static int knapsack3(int[] weight, int[] value, int n, int w) {