HDU2955-Robberies

简介:
Robberies

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

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.
 
Sample Input
3
0.04 3
1 0.02
2 0.03
3 0.05
0.06 3
2 0.03
2 0.03
3 0.05
0.10 3
1 0.03
2 0.02
3 0.05
 
Sample Output
2
4
6
 

动态规划
AC代码:

//用成功逃走的概率当做价值,银行的总钱数当做背包容量 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
   int M;//钱量 
   float P;//不被抓概率 
}dp[110];
float f[10010];//最大的钱量为100*100=10000; 
int max(int n,int m)
{return n>m?n:m;}
int main()
{
    int i,j,T,n,m,sum;
    float x,Psum;
    scanf("%d",&T);
    while(T--)
    {
       memset(dp,0,sizeof(dp));
       memset(f,0,sizeof(f));
       scanf("%f %d",&x,&m);
       Psum=1-x;//最小逃脱率,低于这个就逃不了了 
       sum=0;
       for(i=0;i<m;i++)
       {
          scanf("%d %f",&dp[i].M,&dp[i].P);
          sum+=dp[i].M;
          dp[i].P=1-dp[i].P;//逃脱率 
       }
       
       f[0]=1;//抢0块大洋肯定不被抓
       
       for(i=0;i<m;i++)
       {
          for(j=sum;j>=dp[i].M;j--)
          f[j]=max(f[j],f[j-dp[i].M]*dp[i].P);//f[j]表示抢j块大洋的最大的逃脱概率,条件是f[j-q[i].money]可达,也就是之前抢劫过;
       }
       for(i=sum;i>=0;i--)
       {
          if(f[i]>=Psum)
          {break;}
       }
       printf("%d\n",i);
    }
    return 0;
}

相关文章
|
7月前
|
Java 测试技术
HDU-1233-还是畅通工程
HDU-1233-还是畅通工程
41 0
|
算法 Java 文件存储
|
Java 测试技术
HDU 1847
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3204    Accepted Submission(s): 2008 Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此。
854 0
|
人工智能 BI Java
HDU 1003
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 105228    Accepted Submission(s): 242...
898 0
HDU&#160;1166
Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营 地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。
1089 0
hdu 1754 I Hate It
点击打开链接hdu 1754 思路: 线段树+单点更新 分析: 1 线段树的水题 代码: /************************************************ * By: chenguolin ...
787 0
hdu 1298 T9
点击打开链接hdu 1298 题意:题目说的是在那遥远的星球有一款叫诺基亚的手机,键盘采用题目的图的样式。给定n个单词的出现的概率,规定是相加的比如hell出现为4,hello概率为3则hell的概率为7。
758 0