链接:
https://vjudge.net/problem/LightOJ-1079#author=feng990608
题意:
As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks. He wants to make a calculated risk, and grab as much money as possible. But his friends - Hermione and Ron have decided upon a tolerable probability P of getting caught. They feel that he is safe enough if the banks he robs together give a probability less than P.
思路:
概率,把小于最大值,变成大于最小概率,用背包搞一下就行,之前刷背包刷到过,现在居然忘了..
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
double Dp[100010], P[110];
int M[110];
int n;
int main()
{
int t, cnt = 0;
scanf("%d", &t);
while (t--)
{
memset(Dp, 0, sizeof(Dp));
double p;
int sum = 0;
scanf("%lf%d", &p, &n);
for (int i = 1;i <= n;i++)
scanf("%d%lf", &M[i], &P[i]), sum += M[i];
p = 1-p;
Dp[0] = 1.0;
for (int i = 1;i <= n;i++)
{
for (int j = sum;j >= M[i];j--)
Dp[j] = max(Dp[j], Dp[j-M[i]]*(1-P[i]));
}
int res = 0;
for (int i = sum;i >= 0;i--)
if (Dp[i] >= p)
{
res = i;
break;
}
printf("Case %d: %d
", ++cnt, res);
}
return 0;
}