The crowd is flooded, you and I can't tell. A goose goes by, the past is like yesterday. Only hope to leave not much, and then reward the prosperity of fireworks.
Title Description
Zhang Qiman: "the number of sorcery stones in magic stone mines seems to be enough, but in fact, the number of each kind of magic stone is limited."
Li Xulin: "so we need to change our packaging strategy."
There are N(N < 10) kinds of magic stones and a backpack with a capacity of V (0 < V < 200). The first kind of magic stone has at most n[i] pieces available, each occupied space is c[i], the value is w[i]. The total number of items does not exceed 50. Find out which magic stones will be packed into the backpack so that the total capacity of these items does not exceed the backpack volume, and the total value is maximum.
input
The first action consists of two numbers, V and N. The following N acts on the space, value and quantity of each item.
output
The sum of maximum value.
sample input
Duplicate sample data
8 2 2 100 4 4 100 2
sample output
400
#include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <vector> #include <ctime> #include <cctype> #include <bitset> #include <utility> #include <sstream> #include <complex> #include <iomanip> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; int N,V,dp[210]; struct node { int n;//space int c;//value int w;//Number } p[210]; int main() { scanf("%d%d",&V,&N); for(int i=1; i<=N; i++) scanf("%d%d%d",&p[i].n,&p[i].c,&p[i].w); for(int i=1; i<=N; i++) { if(p[i].w*p[i].n>=V) { for(int j=p[i].n; j<=V; j++) dp[j]=max(dp[j],dp[j-p[i].n]+p[i].c); } for(int k=1; k<p[i].w; p[i].w-=k,k=k*2) for(int j=V; j>=k*p[i].n; j--) dp[j]=max(dp[j],dp[j-k*p[i].n]+p[i].c*k); for(int j=V; j>=p[i].n*p[i].w; j--) dp[j]=max(dp[j],dp[j-p[i].w*p[i].n]+p[i].c*p[i].w); } printf("%d\n",dp[V]); return 0; }