国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

HDU 2955

2019-11-08 02:28:54
字體:
來源:轉載
供稿:網(wǎng)友

Robberies

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22261    Accepted Submission(s): 8232

PRoblem Description

The 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 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, 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.

 

 

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 be 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 is Pj .

 

 

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 Constraints0 < T <= 1000.0 <= P <= 1.00 < N <= 1000 < Mj <= 1000.0 <= Pj <= 1.0A 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

 

題解:還是屬于0-1背包問題,用dp[j]表示偷到j元逃跑的概率。

狀態(tài)轉移方程

Dp[j]=max(dp[j],dp[j-Bag[i].v]*(1-Bag[i].p));

 

 

AC代碼:

#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

 

struct bag

{

    int v;

    double p;

}Bag[10010];

double dp[10010];

 

int main()

{

    int T,N;

    double P;

    scanf("%d",&T);

    while(T--)

    {

        scanf("%lf %d",&P,&N);

        int sum=0;

        for(int i=0;i<N;i++)

        {

            scanf("%d%lf",&Bag[i].v,&Bag[i].p);

            sum+=Bag[i].v;

        }

        memset(dp,0,sizeof(dp));

        dp[0]=1;

        for(int i=0;i<N;i++)

        {

            for(int j=sum;j>=Bag[i].v;j--)

            {

                dp[j]=max(dp[j],dp[j-Bag[i].v]*(1-Bag[i].p));

            }

        }

        for(int i=sum;i>=0;i--)

        {

            if(dp[i]>1-P)

            {

                printf("%d/n",i);

                break;

            }

        }

    }

    return 0;

}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 文水县| 徐汇区| 和政县| 吐鲁番市| 望江县| 渝北区| 徐水县| 衡阳县| 邢台市| 龙泉市| 微山县| 长岛县| 洪泽县| 龙井市| 水城县| 渝北区| 张家口市| 昔阳县| 沾益县| 建始县| 大宁县| 淄博市| 吉安县| 天峻县| 密山市| 锡林浩特市| 康乐县| 鹿泉市| 上虞市| 修水县| 无为县| 嘉定区| 高陵县| 百色市| 宁阳县| 雷波县| 安康市| 集贤县| 兴国县| 营口市| 银川市|