Background: The main idea is to understand the binary application. Next time you write a backpack nine you should make the code a little bit more and avoid mistakes.
Idea: F[i]=mas{f[i-kc[i]]+kw[i] | 0 =< k <= Mi}, for each capacity to seek its maximum value, because the value and cost is equal, so the value can only be less than equal to the cost, those values equal to the cost is the loss of words can constitute this number.
Learning: 1. Both value and expense are self-worth cases and can be used to determine whether these numbers can form another number.
#include <cstdio> #include <iostream> #include <cstring>using namespace Std;int c[109][2],f[100009]; int main (void) {int n,m; while (scanf ("%d%d", &n,&m) && n*n+m*m) {for (int i=0;i < n;i++) scanf ("%d", &c[i][0]); for (int i=0;i < n;i++) scanf ("%d", &c[i][1]<span id= "Transmark" ></span>); memset (f,0,sizeof (F)); for (int i=0;i < n;i++) {if (c[i][0]*c[i][1] >= m) {for (int j=c[i][0];j <= m;j++) { F[j]=max (F[j],f[j-c[i][0]]+c[i][0]); }}else{int K=1,key; while (K < c[i][1]) {key=k*c[i][0]; for (int j=m;j >= key;j--) F[j]=max (F[j],f[j-key]+key); C[i][1]-=k; k*=2; } Key=c[i][1]*c[i][0]; for (int j=m;j >= key;j--) F[j]=max (F[j],f[j-key]+key); }} int count=0; for (int i=1;i <= m;i++) if (f[i] = = i) count++; printf ("%d\n", count); } return 0;}
HDU 2,844 Multi-weight backpack