这道题用dp(i)表示用完i万元得不到一个off的最小概率,状态转移方程: dp[j] = min(dp[j], dp[j-sch[i].a] * sch[i].b);
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <iostream>
#include <sstream>
using namespace std;
#define INF 1e8
struct School{
int a;
double b;
}sch[10005];
double dp[10005];
int main()
{
// freopen("in.txt", "r", stdin);
int n, m;
while(cin >> n >> m)
{
if(n == 0 && m == 0)
break;
for(int i = 0; i < m; i++)
{
cin >> sch[i].a >> sch[i].b;
sch[i].b = 1.0 - sch[i].b;
}
for(int i = 0; i <= n; i++)
dp[i] = INF;
dp[0] = 1.0;
for(int i = 0; i < m; i++)
for(int j = n; j >= sch[i].a; j--)
if(dp[j - sch[i].a] == INF)
continue;
else
dp[j] = min(dp[j], dp[j-sch[i].a] * sch[i].b);
double mins = 1.0;
for(int i = n; i >= 0; i--)
mins = min(mins, dp[i]);
printf("%.1f%%\n", (1.0 - mins) * 100);
}
return 0;
}