将多重背包硬拆成01背包。
结合map,来算方案数。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
const int N = 1e5;
int n,m;
map<int,int> mp;
int v[N],w[N];
int s;
int t;
int f[N];
int main(){
for(int i = 1; i <= 6; i++){
cin >> s;
if(i <= 3){
while(s--){
v[++t] = i;
}
}
else{
if(i == 4){
while(s--){
v[++t] = 5;
}
}
if(i == 5){
while(s--){
v[++t] = 10;
}
}
if(i == 6){
while(s--){
v[++t] = 20;
}
}
}
}
for(int i = 1; i <= t; i++){
for(int j = 1000; j >= v[i]; j--){
f[j] = max(f[j],f[j - v[i]] + v[i]);
if(!mp[f[j]] && f[j] != 0){
mp[f[j]]++;
}
}
}
cout << "Total=" << mp.size() << endl;
return 0;
}