Advertisement

算法设计回溯法用于解决01背包问题

阅读量:
复制代码
    //0-1背包问题 回溯法求解
    #include<bits/stdc++.h>
    #include <iostream>
    
    using namespace std; 
    
    template<class Typew,class Typep>
    class Knap
    {
    	public:
    		Typep Bound(int i);
    		void Backtrack(int i);
    	
    		Typew c;	//背包容量
    		int n;		//物品数
    		Typew *w;	//物品重量数组
    		Typep *p;	//物品价值数组
    		Typew cw;	//当前重量
    		Typep cp;	//当前价值
    		Typep bestp;//当前最后价值
    
    };
    
    template<class Typew,class Typep>
    
    Typep Knapsack(Typep p[],Typew w[],Typew c,int n);
    
    template <class Type>
    
    inline void Swap(Type &a,Type &b);

全部评论 (0)

还没有任何评论哟~