背包模板

来源:互联网 发布:乐山电视台网络电视 编辑:程序博客网 时间:2024/06/06 02:49
#include <iostream>#include <algorithm>#include <string.h>#include <cmath>#include <stdio.h>#include <vector>#include <map>#include <queue>#include <utility>typedef long long ll;using namespace std;const int MAX = 100000000;int a[MAX], dp[MAX];void Zero_packpage(const int& volume, const int& value, const int& cost) {    for (int i = volume; i >= value; --i)        dp[i] = max(dp[i], dp[i-cost] + value);}void Compelet_packpage(const int& volume, const int& value, const int& cost) {    for (int i = cost; i <= volume; ++i)        dp[i] = max(dp[i], dp[i-cost] + value);}void Multip_package(const int& volume, const int& value, const int& cost, const int& many) {    if (many * cost >= volume)        Compelet_packpage(volume, value, cost);    else {        int k = volume, i = 1;        while (k > i) {            Zero_packpage(volume, value*i, cost*i);            k -= i;            i <<= 1;        }        Zero_packpage(volume, value*k, value*k);    }    return;}int main(){    }

0 0