`
leonzhx
  • 浏览: 793664 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
阅读更多

1.  Problem Denition

    --  Input: n items. Each has a:

        a) Value vi (nonnegative)

        b) Size wi (nonnegative and integral)

        Capacity W (a nonnegative integer)

    --  Output: A subset S of {1, 2, ... , n} that maximizes sum(i in S) {vi} subject to Sum(i in S) {wi} <= W.

 

2.  A Dynamic Programming Algorithm

    --  Formulate recurrence [optimal solution as function of solutions to "smaller subproblems"] based on a structure of an optimal solution.

    --  Let S = a max-value solution to an instance of knapsack.

    --  Case 1: Supose item n not in S. ==> S must be optimal with the first n-1 items (same capacity W) because If S* were better than S with respect to 1st n - 1 items, then this equally true w.r.t. all n items [contradiction]

    --  Case 2: Suppose item n in S. Then S - {n} is an optimal solution with respect to the 1st n - 1 items and capacity W - wn. Because If S* has higher value than S -{n} and its total size <= W - wn,

then S* U {n} has size <= W and value more than S [contradiction]

 

3.  The Subproblems

    --  Let V(i , x) = value of the best solution that:

       (1) uses only the first i items

       (2) has total size <= x

    --  For i in {1, 2, ... , n} and only x,

        V(i , x) = max {V(i-1 , x) (case 1, item i excluded), vi + V(i-1 , x-wi) (case 2, item i included) }

    --  Edge case: If wi > x, must have V(i , x) = V(i-1 , x)

    --  Identify the subproblems:

        a) All possible prefixes of items {1, 2, ... , i} , i in { 0, 1, 2, ..., n}

        b) All possible (integral) residual capacities x in {0, 1, 2, ... , W}

    --  Use recurrence to systematically solve all problems:

        a) Let A = 2-D array

        b) Initialize A[0 , x] = 0 for x = 0, 1, ... , W

        c) For i = 1, 2, ... , n

                For x = 0, 1, ... , W

                    A[i , x] := max { A[i - 1 , x] , A[i - 1; x - wi ] + vi } (Ignore second case if wi > x)

        d) Return A[n,W]

    --  Running Time: O(nW)

 

4.  Example :



 

  • 大小: 44.6 KB
分享到:
评论

相关推荐

    FPTAS for the Knapsack Problem

    背包问题近似算法PTAS和FPTAS. The Knapsack Problem and Fully Polynomial Time Approximation Schemes (FPTAS). 作者: Katherine Lai, Prof. M. X. Goemans

    An improved genetic algorithm for the multi constrained 0–1 knapsack problem

    在本文中,作者提出了一种改进的混合遗传算法(Hybrid Genetic Algorithm, HGA)来解决多约束0-1背包问题(Multiconstrained 0-1 Knapsack Problem, MKP)。MKP是一个著名的NP完全组合优化问题,其定义如下: 目标...

    华南理工大学计算机全英班算法设计实验

    4)And compare the results between the knapsack problem and the 0/1 knapsack problem. 5)Write down the report in which there should be the execution results of the program. Experiment 3 The Prim...

    Best-First-Tree 0-1 Knapsack

    best-first-search branch and bound algorithm for the knapsack problem

    np难问题近似算法(绝版好书)

    knapsack problem 9.3.2 The minimum makespan and the technique of dual approximations 9.3.3 Geometric packing and covering--the shifting technique 9.4 Best: unless NP = P 9.4.1 The k-center problem ...

    0-1 pack_rememberscj_C++_

    0-1 Detailed explanation of the knapsack problem algorithm and all the codes can provide an effective reference

    0-1-knapsack-problem-master (22).zip

    0-1 背包问题(0-1 Knapsack Problem)是计算机科学中的一个经典优化问题,尤其在算法竞赛和网络安全的CTF(Capture The Flag)比赛中常常出现。在这个问题中,我们有一组物品,每种物品都有一个重量和一个价值,...

    算法上机!!

    Solve the problem both as fractional knapsack and 0/1 knapsack. A simple scheduling problem. We are given jobs j1, j2… jn, all with known running times t1, t2… tn, respectively. We have a single ...

    0-1-knapsack-problem-master (44).zip

    【标题】"0-1-knapsack-problem-master (44).zip" 提到的是一个与0-1背包问题相关的代码库,可能是为CTF(Capture The Flag)网络安全竞赛中的Web挑战准备的。CTF比赛是一种流行的信息安全竞赛,参与者通过解决各种...

    01背包问题-huiying_hw4.rar

    1.Implement a GA optimization procedure for 0/1 knapsack problem: - For the given list of 10, 15, 20, 740items, load the knapsack with weight capacity 200 and volume of 500. Each itemcan be present ...

    The-Knapsack-Problem-Dynamic-programming:动态规划是一种求解优化问题的方法

    背包问题动态规划背包问题是组合优化中的一个问题: 给定一组物品,每个物品都有一个质量和一个价值,确定每个物品要包含在一个集合中的数量,以便总重量小于或等于给定的限制,并且总价值尽可能大。...

    AN IMPROVED NICHE GENETIC ALGORITHM

    A simulated annealing based niche genetic algorithm (SANGA) has been presented to strength the optimization ability of niche genetic algorithm (NGA). The improved idea is to define ...problem.

    knapsack管理系统基于python (28).zip

    在计算机科学和编程领域,"背包问题"(Knapsack Problem)通常是一个经典的优化问题,涉及在给定容量限制的情况下,如何选择物品以最大化总价值。这里的“管理系统”可能是指一个用于处理这类问题的应用程序,它可能...

    The Algorithm Design Manual (2rd Edition)

    13.10 Knapsack Problem 13.11 Discrete Fourier Transform 14 Combinatorial Problems 14.1 Sorting 14.2 Searching 14.3 Median and Selection 14.4 Generating Permutations 14.5 Generating Subsets ...

    A novel approach for radio resource management in multi-dimensional heterogeneous 5G networks

    A GRA-BKP (Grey Relational Analysis-Bounded Knapsack Problem) scheme was proposed for the radio resource management of the 5G networks. It consists of two steps, access selection and admission control...

    Programming Interview Problems and Algorithms in Ruby

    Tree Serialization, Finding the Top k Elements of Data Streams, MapReduce, Partial Sorting, the Skyline Problem, DFS, BFS and Topological Sorting of Dags, the Alternative Alphabet and the Phone Words...

    dyer1984.pdf

    “An algorithm for solving the linear program associated with the multiple-choice knapsack problem described”说明文档中描述了一种用于求解与多重选择背包问题相关联的线性规划问题的算法。线性规划是数学...

Global site tag (gtag.js) - Google Analytics