hdu 2955

水DP,不说了


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int m[110];
double pd[110];
double f[10010];
int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        double p;
        int n;
        scanf("%lf%d", &p, &n);
        p = 1 - p;
        int sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%d%lf", &m[i], &pd[i]);
            pd[i] = 1 - pd[i];
            sum += m[i];
        }
        for(int i = 1; i <= sum; i++)  f[i] = -1.0;
        f[0] = 1;//逃脱的概率
        for(int j = 0; j < n; j++)
        {
            for(int i = sum; i >= 1; i--)
            {
                if(i < m[j])  continue;
                double t = f[i-m[j]] * pd[j];
                if(f[i-m[j]] != -1 && t >= p)
                {
                    f[i] = max(f[i], t);
                }
            }
        }
        int rmax = 0;
        for(int i = 1; i <= sum; i++)
            if(f[i] >= 0)  rmax = i;
        printf("%d\n", rmax);
    }
    return 0;
}


你可能感兴趣的:(hdu 2955)