Topic links
The main topic: Ftiasch has N items, volume is W1, W2, ..., WN. As a result of her negligence, article I was lost. "There are several ways to use the rest of the N-1 to fill an X-volume backpack. "– This is a classic question. She recorded the answer as count (i, x), want to get all 1 <= i <= N, 1 <= x <= m of Count (i, X) table
Solution: F[x] f[x] represents the number of scenarios that happen to be filled with X-volume, this 01 backpack
Consider the case of the optional item I below
G[X] is the number of solutions that do not select the current item I exactly fill the X volume
Then sort the discussion
1. x<w[i] x g[x]=f[x]
2. x≥w[i] x \geq w[i) equals the total scheme minus the number of scenarios selected for I
So how do I get the number of options for the current item I just fill the x volume?
You can divide this into two steps: Do not select the current item I exactly fill x-w[i] Volume Select current Item I
IE G[x]=f[x]-g[x-w[i]]
My harvest: a special posture
#include <bits/stdc++.h> using namespace std;
int n,m;
int w[2010];
Long Long f[2010],g[2010];
void ZeroOne () {f[0]=1;
for (int i=1;i<=n;i++) for (int j=m;j>=w[i];j--) f[j]= (F[j]+f[j-w[i]])%10;
} void Calc () {for (int. i=1;i<=n;i++) {for (int j=0;j<w[i];j++) G[J]=F[J];
for (int j=w[i];j<=m;j++) g[j]= (f[j]-g[j-w[i]]+10)%10;
for (int j=1;j<=m;j++) printf ("%d", g[j]);
Putchar (' \ n ');
}} void Work () {ZeroOne ();
Calc ();
} void Init () {scanf ("%d%d", &n,&m);
for (int i=1;i<=n;i++) scanf ("%d", &w[i]);
} int main () {init ();
Work ();
return 0; }