厚度2955

原创 2012年03月21日 22:22:10

Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3367    Accepted Submission(s): 1251


Problem 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.
 

Input
The first line of input gives T, the number of cases. For each scenario, the first line of input gives a floating point number P, the probability Roy needs to be below, and an integer N, the number of banks he has plans for. Then follow N lines, where line j gives an integer Mj and a floating point number Pj . 
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
 

Output
For each test case, output a line with the maximum number of millions he can expect to get while the probability of getting caught is less than the limit set.

Notes and Constraints
0 < T <= 100
0.0 <= P <= 1.0
0 < N <= 100
0 < Mj <= 100
0.0 <= Pj <= 1.0
A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
struct BANK
{
    int money;
    double risk;
}bank[105];
double dp[10009];//dp[j]   rob  money j,the risk of not being caught is dp[j]
double MAX(double a,double b)
{
       if (a > b) return a;
       return b;
}
int main()
{
    int T,N; double P;
    cin>>T;
    while (T--)
    {
        int sum=0;
        scanf("%lf %d",&P,&N);
        for (int i=1;i<=N;i++)
        {
            cin>>bank[i].money>>bank[i].risk;
            sum+=bank[i].money;
        }
        P=1-P;//means security
        for (int i=0;i<=sum;i++)     dp[i]=0;
        dp[0]=1;
        for (int i=1;i<=N;i++)
        {
            for (int j=sum; j>=bank[i].money;j--)
            {
                dp[j]=MAX(dp[j],dp[j-bank[i].money]*(1-bank[i].risk));
            }
        }
        for (int i=sum;i>=0;i--)
        {
            if (dp[i] >= P)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
}



相关文章推荐

厦华彩电TF2955电路图

  • 2010年03月28日 14:50
  • 159KB
  • 下载

2N3055 MJ2955制作的50 watts功放

  • 2016年02月27日 10:47
  • 169KB
  • 下载

人生最重要的时候,从30岁到35岁:为生命多积累一些厚度

常常思考一个问题:是不是考虑做2年开发,打2年酱油,然后结婚生子,这样到底行不行?无论你是男是女,人生是一场独自修行的道路。如果在可以选的时候,还是选择靠自己吧。 无论你是要养家还是要实现人生价...
  • endygeu
  • endygeu
  • 2012年12月13日 10:39
  • 224

2955B使用说明

  • 2015年01月14日 19:03
  • 1.7MB
  • 下载

PCB设计铜铂厚度、线宽和电流关系

原文地址::http://www.360doc.com/content/12/0702/23/8729276_221812135.shtml 相关文章 1、PCB设计铜箔厚度、线宽和电流关系---...

PCB设计铜箔厚度、线宽和电流关系-

http://www.360doc.com/content/10/1029/11/3705128_64961557.shtml 一、计算方法如下: 先计算Track的截面积,大部分...

从30-35岁:为你的生命多积累一些厚度

常常思考一个问题:是不是考虑做2年开发,打2年酱油,找个人嫁了了事,这样到底行不行? 无论你是男是女,人生是一场独自修行的道路。如果在可以选的时候,还是选择靠自己吧。 无论你是要养家还是要实现人生...
  • wcppcw
  • wcppcw
  • 2012年12月19日 13:28
  • 315

转:PCB设计铜铂厚度、线宽和电流关系

以下总结了网上八种电流与线宽的关系公式,表和计算公式,虽然各不相同(大体相近),但大家可以在实际的PCB板设计中,综合考虑PCB板的大小,通过电流,选择一个合适的线宽。 一、PCB电流与线宽PCB载流...

从30岁到35岁:为你的生命多积累一些厚度

转自:http://www.cnblogs.com/newstart/archive/2012/12/07/2806580.html 从30岁到35岁:为你的生命多积累一些厚度 常...

PCB设计铜铂厚度、线宽和电流关系

该文章转载于http://www.cnblogs.com/wangh0802PositiveANDupward/archive/2012/12/24/2830540.html。 一、计算方法如下:...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:厚度2955
举报原因:
原因补充:

(最多只允许输入30个字)