Dynamic Planning 1-robberies-poj-2955

Source: Internet
Author: User
Robberies

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


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

Probability is involved here, rather than simply adding. The probability of escape can be calculated. This is a continuous multiplication, which is relatively convenient.

It is different from the ordinary 01 backpack problem. It is used here.

OPT [J] indicates the maximum escape probability when obtaining money J.

Finally, find the maximum J that meets the requirements.

# Include <iostream> using namespace STD; int Marr [101]; double Parr [101]; int K, N; double up; int ans; double opt [100001]; // OPT [J] indicates the maximum escape probability of money J. Int sum; int main () {CIN> K; while (k --) {double TB; cin> up> N; sum = 0; For (INT I = 0; I <n; I ++) {// calculate the sum of all bank money and CIN> Marr [I]> Parr [I]; sum + = Marr [I];} OPT [0] = 1.0; for (INT I = 1; I <= sum; I ++) OPT [I] = 0.0; For (INT I = 0; I <n; I ++) {for (Int J = sum; j> = Marr [I]; j --) {TB = OPT [J-Marr [I] * (1-Parr [I]); If (Tb> OPT [J]) OPT [J] = Tb ;}} for (INT I = sum; I> = 0; I --) {// traverse, find the maximum amount of money that meets the requirements if (1-OPT [I] <= up) {cout <I <Endl; 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.