Speakless is now worth tens of thousands of US dollars. He wants to apply to go abroad. Each school has a different application fee. Speakless is likely to get an offer from this school. Evaluate the maximum likelihood that Speakless will receive at least one offer.
Train of Thought: The maximum possibility of receiving at least one offer is not good. It can be converted to the minimum possibility of not receiving at all points. In this way, we can use the 01 backpack to solve the problem ~
Note: The probability is multiplication rather than addition;
Because the minimum value is obtained, the initial value of array f needs to be set to 1 (because the maximum probability is 1, and the probability of not receiving an array f is also 1 ).
[Cpp]
# Include <stdio. h>
# Define maxn11111
Double f [maxn];
Int main ()
{
Int m, n, w [maxn];
Double v [maxn];
While (scanf ("% d", & n, & m) & (n | m ))
{
Int I, j;
For (I = 1; I <= m; I ++)
{
Scanf ("% d % lf", & w [I], & v [I]);
V [I] = 1-v [I]; // the probability that an offline payment fails to be received because you need to calculate the probability that no change is received.
}
For (I = 0; I <= n; I ++)
F [I] = 1; // set the initial value to 1.
For (I = 1; I <= m; I ++)
For (j = n; j> = w [I]; j --)
If (f [j]> f [j-w [I] * v [I]) // calculates the minimum value.
F [j] = f [j-w [I] * v [I];
Printf ("%. 1lf % \ n", 100 * (1-f [n]);
}
Return 0;
}
Author: sdc1992