This question is a very basic 0/1 knapsack problem, in order to make the solution is very simple, can be asked in the topic the maximum probability of conversion into the minimum probability of admission, so 1-dp[n] is the maximum probability of at least one offer. State equation
is: Dp[j]=min{dp[j],dp[j-price[i]]*chance[i]};
1#include"iostream"2#include"stdio.h"3#include"algorithm"4#include"string.h"5#include"Cmath"6#include"Queue"7 #defineMX 100058 using namespacestd;9 intPRICE[MX];Ten DoubleCHANCE[MX]; One DoubleDP[MX]; A intMain () - { - intn,m,i,j,k; the while(cin>>n>>m,n| |m) - { - for(i=1; i<=m;i++) - { +Cin>>price[i]>>Chance[i]; -chance[i]=1-Chance[i]; + } A for(i=0; i<=n;i++) dp[i]=1; at for(i=1; i<=m;i++) - { - for(j=n;j>=price[i];j--) - { - if(Dp[j]>dp[j-price[i]]*chance[i]) dp[j]=dp[j-price[i]]*Chance[i]; - } in } -printf"%.1lf%%\n",(1-dp[n]) * -); to } + return 0; -}
View Code
HDU I need A offer!