update at 2022-03-24 09:32:13 by ehlxr
This commit is contained in:
		@@ -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) {
 | 
			
		||||
		Reference in New Issue
	
	Block a user