zoukankan      html  css  js  c++  java
  • LightOJ-1079-Just another Robbery(概率, 背包)

    链接:

    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;
    }
    
  • 相关阅读:
    poj3436(ACM Computer Factory)
    一位ACMer过来人的心得
    poj1459(Power Network)
    (转)网络流—最大流(Edmond-Karp算法)
    poj1611(The Suspects)
    构建之法阅读笔记01
    第三周总结
    全国疫情可视化地图
    第二周总结
    作业--数组(大数)
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11450508.html
Copyright © 2011-2022 走看看