The question is to give you a few numbers, then give you the available numbers, and then randomly find a few numbers to accumulate,
Let me calculate the number that can be accumulated!
Solution: First initialize the backpack to-1, calculate it with multiple backpacks, and finally search for it. If bb [I] = I, it means that I can get this number! The number of records that can be reached by a cyclic computing task is ready for output!
# Include <stdio. h>
# Define max (a, B) a> B? A: B
Int bb [500000];
Int vv;
Void shun (int cost, int weight)
{
Int I;
For (I = cost; I <= vv; I ++)
Bb [I] = max (bb [I], bb [I-cost] + weight );
}
Void ni (int cost, int weight)
{
Int I;
For (I = vv; I> = cost; I --)
Bb [I] = max (bb [I], bb [I-cost] + weight );
}
Int main ()
{
Int n, I, k, v [5000], amount [5000], ans;
While (scanf ("% d", & n, & vv), n + vv)
{
For (I = 1; I <= vv; I ++)
Bb [I] =-1;
For (I = 0; I <n; I ++)
Scanf ("% d", & v [I]);
For (I = 0; I <n; I ++)
Scanf ("% d", & amount [I]);
For (I = 0; I <n; I ++)
{
If (amount [I] * v [I]> = vv)
Shun (v [I], v [I]);
Else
{
K = 1;
While (k <amount [I])
{
Ni (k * v [I], k * v [I]);
Amount [I]-= k;
K * = 2;
}
Ni (amount [I] * v [I], amount [I] * v [I]);
}
}
Ans = 0;
For (I = 1; I <= vv; I ++)
If (bb [I] = I)
Ans ++;
Printf ("% d \ n", ans );
}
Return 0;
}