HDU 2955 Robberies DP

Source: Internet
Author: User

robberiesTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U

Description

The aspiring Roy the robber have 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 had 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, had decided upon a tolerable probability of getting caught. She feels that he's 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 is 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's Pj.

Output

For each test case, output a line with the maximum number of millions he can expect to get while the probability of gettin G 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 your may assume that all probabilities be independent as the police have very lo W 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



#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue> #include <vector> #include <iomanip> #include <math.h> #include <map>using namespace STD; #define FIN freopen ("Input.txt", "R", stdin), #define FOUT freopen ("Output.txt", "w", stdout); #define INF 0x3f3f 3f3f#define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1typedef long long ll;const int MAXN=10005;double dp[    Maxn];int m[105];d ouble p[105];int Main () {//fin int T;    scanf ("%d", &t);        while (t--) {int n,total=0;        Double AP;        scanf ("%lf%d", &ap,&n);            for (int i=0;i<n;i++) {scanf ("%d%lf", &m[i],&p[i]);        total+=m[i];//first find out how much money you can get Memset (dp,0,sizeof (DP));        Dp[0]=1; for (int i=0;i<n;i++) for (int j=total;j>=m[i];j--) {Dp[j]=max (dp[j],dp[j-m[i]]* (1-p[i])); /The probability of not being caught} int ans for (int i=total;i>=0;i--) {if (dp[i]>=1-ap) {ans=i;break;}    Output} printf ("%d\n", ans) from the start cycle that can take the most money if it can not be caught; }}

  



HDU 2955 Robberies DP

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.