01 backpack, probability

Source: Internet
Author: User

Original question http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2955

Robberies

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 11820 accepted submission (s): 4398


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


 

Inputthe first line of input gives t, the number of instances. 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. 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.


 

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

Notes and constraints
Zero <t <= 100
0.0 <= P <= 1.0
0 <n <= 100
0 <MJ <= 100
0.0 & lt; = PJ & lt; = 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
30.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 output
246
// Give you a probability, and then there are N groups of data. The integer of each group of data represents money, And the decimal number represents the probability of being captured. // ask, the maximum amount of money can be charged without the probability of being captured. // Train of thought: open a DP array, which indicates the probability that the money will not be caught at the time of N, # include <stdio. h> # include <stdlib. h> # include <malloc. h> # include <limits. h> # include <ctype. h> # include <string. h> # include <string> # include <math. h> # include <algorithm> # include <iostream> # include <stack> # include <queue> # include <deque> # include <vector> # include <set> # include <map> using namespace STD; # define n 100 + 10 double DP [10009]; int sum [N]; Double P [N]; double max (doub Le A, double B) {return A> B? A: B;} int main () {int t, n, I; Double V; while (~ Scanf ("% d", & T) {While (t --) {memset (DP, 0, sizeof (DP); DP [0] = 1; memset (sum, 0, sizeof (SUM); memset (p, 0, sizeof (p); scanf ("% lf % d", & V, & N ); int mark = 0; for (I = 1; I <= N; I ++) {scanf ("% d % lf", & sum [I], & P [I]); Mark + = sum [I]; P [I] = 1-P [I];} Int J; for (I = 0; I <= mark; I ++) {DP [I] = 0;} DP [0] = 1; // it must be safe when 0 yuan is snatched. So the initialization is 1 for (I = 1; I <= N; I ++) {for (j = mark; j> = sum [I]; j --) {DP [J] = max (DP [J], DP [J-sum [I] * (p [I]) ;}} v = 1-V; for (I = mark; I> = 0; I --) {If (DP [I]> = V) {printf ("% d \ n", I ); break ;}}} return 0 ;}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.