hdu2955 Robberies(java)

來源:互聯網
上載者:User

標籤:多少   oid   class   span   double   output   maximum   ++   不能   

題目大意:

先是給出幾組資料,每組資料第一行是總被抓機率p(最後求得的總機率不能大於他,否則被抓),然後是想搶的銀行數n。然後n行,每行分別是該銀行能搶的錢數m[i]和被抓的機率p[i],求在不被抓到的情況下能搶到的錢數;

 

OutputFor 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 Input30.04    31      0.022      0.033      0.050.06    32      0.032      0.033      0.050.10    31      0.032      0.023      0.05 

 

Sample Output246  題目意思:一個小偷想偷銀行的錢,這個小偷偷每家銀行被抓到的機率為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呢?

hdu2955 Robberies(java)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.