[恢]hdu 1203
2011-12-25 11:17:07
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1203
题意:中文。。。
mark:标准01背包。概率正着不好算,算拿不到的概率就好了。
代码:
# include <stdio.h>
double dp[10010] ;
int n, m ;
double min(double a, double b){return a<b?a:b;}
int main ()
{
int i, j, cost ;
double prob ;
while (~scanf ("%d%d", &m, &n) && (m||n))
{
for (i = 0 ; i <= m ; i++) dp[i] = 1 ;
dp[0] = 1 ;
for (i = 0 ; i < n ; i++)
{
scanf ("%d %lf", &cost, &prob) ;
for (j = m ; j >= cost ; j--)
dp[j] = min (dp[j], dp[j-cost]*(1-prob)) ;
}
printf ("%.1lf%%\n", (1.0-dp[m])*100.0) ;
}
return 0 ;
}