http://acm.hdu.edu.cn/showproblem.php?pid=2955
费用为实数的背包问题,可以考虑把费用和价值换一换,把价值看成费用,费用看成价值。其实就是算构成某一种价值的最小(或最大)费用。
我的代码
1 #include <stdio.h>
2 #include <string.h>
3 const int V=10010;
4 double f[V],p[110];
5 int m[110];
6 int main()
7 {
8 int T,i,j,n,v;
9 double pp;
10 scanf("%d",&T);
11 while (T--)
12 {
13 v=0;
14 scanf("%lf%d",&pp,&n);
15 for (i=1;i<=n;i++)
16 {
17 scanf("%d%lf",&m[i],&p[i]);
18 v+=m[i];
19 }
20 memset(f,0,sizeof(f)); f[0]=1;
21 for (i=1;i<=n;i++)
22 for (j=v;j>=m[i];j--) f[j]>?=f[j-m[i]]*(1-p[i]);
23 while (1-f[v]>=pp) v--;
24 printf("%d\n",v);
25 }
26 return 0;
27 }