—————————————————————————————————————————————————————————————————————————————
这个题是典型的的0-1背包问题 所不同的是采用了记忆化搜索 使得最终值出现在 满足概率的最后 这个题 其实没多大难度 主要还是状态转移方程在求解多路径相同问题时发了功效 我认为这个是个很好的0-1模型模板~~~~浪里格朗~~~
____________________________________________________________________________________________________________________________________
#include <stdio.h>
#include <algorithm>
using namespace std;
struct Bank
{
int money;
double p;
} bank[10005];
int main()
{
int n,t;
double p;
scanf("%d",&t);
while(t--)
{
scanf("%lf%d",&p,&n);
p = 1-p;
int i,j,sum = 0;
for(i = 0; i<n; i++)
{
scanf("%d%lf",&bank[i].money,&bank[i].p);
bank[i].p = 1-bank[i].p;
sum+=bank[i].money;
}
double dp[10005]= {1.0};
for(i = 0; i<n; i++)
{
for(j = sum; j>=bank[i].money; j--)
{
dp[j] = max(dp[j],dp[j-bank[i].money]*bank[i].p);
}
}
//for(i=0;i<sum;i++)printf("%lf ",dp[i]);
//printf("\n");
//printf("%lf %d\n",p,sum);
for(i = sum; i>=0; i--)
{
if(dp[i]-p>0.000000001)
{
printf("%d\n",i);
break;
}
}
}
return 0;
}