AC链接

http://acm.hdu.edu.cn/showproblem.php?pid=2955

Description

The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, before retiring to a comfortable job at a university.For a few months now, Roy has been assessing the security of various banks and the amount of cash they hold. He wants to make a calculated risk, and grab as much money as possible.His mother, Ola, has decided upon a tolerable probability of getting caught. She feels that he is safe enough if the banks he robs together give a probability less than this.

题目大意

给你n个银行,银行的钱数和被抓的概率,要求被抓概率小于k且拿到更多的钱

题目分析

考虑将被抓概率化为安全概率,容易发现概率是可以相乘的,以这个为依据做砝码称重问题。

题目代码

#include<bits/stdc++.h>
using namespace std;
double f[12000];
int wei[1200];
double c[1200];

int main(){
    int t; cin >> t;
    while(t--){
    memset(f,0,sizeof(f));
    double db; int n;
    cin >> db >> n;
    db = 1-db;
    int tot = 0;
    for(int i=1;i<=n;i++){
        cin >> wei[i] >> c[i];
        tot += wei[i];
        c[i] = 1.0-c[i];
    }
    f[0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=tot;j>=wei[i];j--){
        f[j] = max(f[j],f[j-wei[i]]*c[i]);
        }
    }
    for(int i=tot;i>=0;i--){
        if(f[i]>=db){cout<<i<<endl;break;}
    }
    }
    return 0;
}


分享至ヾ(≧∇≦*)ゝ:
分类: 所有

发表评论

电子邮件地址不会被公开。 必填项已用*标注

你是机器人吗? =。= *