zoukankan      html  css  js  c++  java
  • hdu2955 Robberies(java)

    题目大意:

    先是给出几组数据,每组数据第一行是总被抓概率p(最后求得的总概率不能大于他,否则被抓),然后是想抢的银行数n。然后n行,每行分别是该银行能抢的钱数m[i]和被抓的概率p[i],求在不被抓到的情况下能抢到的钱数;

    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
     
     
    题目意思:一个小偷想偷银行的钱,这个小偷偷每家银行被抓到的概率为pi,小偷只要偷每一家银行失败的概率小于P就不会被抓到,求小偷不被抓到的情况下最多可以投多少钱?
     
    分析:小偷偷每家银行失败概率是pi,那么成功的概率是(1-pi);给定所偷银行失败概率范围小于p安全,那么只要小偷所偷银行成功概率大于(1-p)则安全;将问题由在最大不被抓概率p内所偷的最钱数,转化为所偷钱数一定的情况下的最大概率.dp[j]表示成功偷取钱数为j情况下的最大概率。dp[j]=max(dp[j],dp[j-m[i]]*(1-pi));
     
    代码:
     1 import java.util.Scanner;
     2 
     3 public class Test1 {
     4 
     5     public static void main(String[] args) {
     6         
     7         double[] dp=new double[10005];
     8         int[] m=new int[105];
     9         double[] p=new double[105];
    10         
    11         Scanner input=new Scanner(System.in);
    12         int t=input.nextInt();
    13         int sum,n,i,j;
    14         double P;
    15         
    16         while(t--!=0) {
    17             
    18             sum=0;
    19             P=input.nextDouble();
    20             P=1-P;
    21             n=input.nextInt();
    22             
    23             for(i=0;i<n;i++) {
    24                 
    25                 m[i]=input.nextInt();
    26                 p[i]=input.nextDouble();
    27                 p[i]=1-p[i];
    28                 sum+=m[i];
    29                 
    30             }
    31             
    32             dp[0]=1;
    33             for(i=0;i<n;i++) {
    34                 
    35                 for(j=sum;j>=m[i];j--) {
    36                     
    37                     dp[j]=Math.max(dp[j],dp[j-m[i]]*p[i]);
    38                     
    39                 }
    40             }
    41             
    42             for(i=sum;i>=0&&dp[i]<P;i--);
    43             
    44             System.out.println(i);
    45             
    46             
    47         }
    48     }
    49 }

    思路是这个思路啊,为啥不能ac呢?

  • 相关阅读:
    CodeForces Gym 100500A A. Poetry Challenge DFS
    CDOJ 486 Good Morning 傻逼题
    CDOJ 483 Data Structure Problem DFS
    CDOJ 482 Charitable Exchange bfs
    CDOJ 481 Apparent Magnitude 水题
    Codeforces Gym 100637G G. #TheDress 暴力
    Gym 100637F F. The Pool for Lucky Ones 暴力
    Codeforces Gym 100637B B. Lunch 找规律
    Codeforces Gym 100637A A. Nano alarm-clocks 前缀和
    TC SRM 663 div2 B AABB 逆推
  • 原文地址:https://www.cnblogs.com/xuzhiyuan/p/7795226.html
Copyright © 2011-2022 走看看