1. First find the smallest failure rate, and then use 1-this failure rate to get the maximum probability of having at least one offer.
2. I feel that this topic should be initialized. . . . .
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int INF = 10010;
int volume[INF];
double value[INF];
double dp[INF];
double MIN(double a,double b)
{
if(a<b)
{
return a;
}
else
{
return b;
}
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)&&(n+m))
{
for(int i=0;i<=n;i++)
{
dp[i]=1;
}
memset(value,0,sizeof(value));
memset(volume,0,sizeof(volume));
for(int i=0;i<m;i++)
{
scanf("%d%lf",&volume[i],&value[i]);
value[i]=1-value[i];
}
for(int i=0;i<m;i++)
{
for(int j=n;j>=volume[i];j--)
{
//cout<<"ok"<<endl;
dp[j]=MIN(dp[j],dp[j-volume[i]]*value[i]);
}
}/*
//cout<<"---------------"<<endl;
for(int i=0;i<=n;i++)
{
//printf("%.1lf%%\n",value[i]*100);
//printf("%.6lf\n",dp[i]);
//printf("%.1lf%%\n",(1-dp[i])*100);
}*/
//cout<<endl;
double ans=1;
for(int i=0;i<=n;i++)
{
ans=MIN(ans,dp[i]);
}
printf("%.1lf%%\n",(1-ans)*100);
}
return 0;
}