10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽

http://acm.hdu.edu.cn/showproblem.php?pid=2955

Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9836    Accepted Submission(s): 3673

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 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 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
 
 #include<stdio.h>
#include<string.h>
int main()
{
int v[];
double f[],w[];
int i,j,n,m;
int T;
scanf("%d",&T);
while(T--)
{
double rate;
int sum=;
scanf("%lf %d",&rate,&n);//rate被抓的概率,1-rate逃脱的概率
for(i=;i<n;i++)
{
scanf("%d %lf",&v[i],&w[i]);
sum+=v[i];
}
memset(f,,sizeof(f));
f[]=;//没偷逃脱的概率为1
for(i=;i<n;i++)
{
for(j=sum;j>=v[i];j--)
{
f[j]=f[j]>f[j-v[i]]*(-w[i])?f[j]:f[j-v[i]]*(-w[i]);//选择最大逃脱概率
}
}
for(i=sum;i>=;i--)
{
if(f[i]>=-rate)
{
printf("%d\n",i);
break;
}
}
}
return ;
}

HDOJ 2955 Robberies (01背包)的更多相关文章

  1. HDOJ.2955 Robberies (01背包+概率问题)

    Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...

  2. hdu 2955 Robberies 0-1背包/概率初始化

    /*Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  3. hdu 2955 Robberies (01背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...

  4. HDU 2955 Robberies(01背包变形)

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. hdu 2955 Robberies (01背包好题)

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. HDU——2955 Robberies (0-1背包)

    题意:有N个银行,每抢一个银行,可以获得\(v_i\)的前,但是会有\(p_i\)的概率被抓.现在要把被抓概率控制在\(P\)之下,求最多能抢到多少钱. 分析:0-1背包的变形,把重量变成了概率,因为 ...

  7. HDU 2955 Robberies --01背包变形

    这题有些巧妙,看了别人的题解才知道做的. 因为按常规思路的话,背包容量为浮点数,,不好存储,且不能直接相加,所以换一种思路,将背包容量与价值互换,即令各银行总值为背包容量,逃跑概率(1-P)为价值,即 ...

  8. HDU 2955 Robberies(01背包)

    Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...

  9. hdoj 2955 Robberies

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. java.lang.NoClassDefFoundError: org/objectweb/asm/Type

    Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/ ...

  2. 更改PATH后,别忘了及时重启或刷新

    在windows环境下配了MinGW gcc编译器,结果编译时总提示找不到头文件.第一反应就是更改环境变量,但是将gcc目录添加到PATH中,再次运行编译依旧报错.多方查找后发现这样一句话:PATH在 ...

  3. Jetty+json-lib库抛异常的问题解决过程(java.lang.NoClassDefFoundError: net/sf/json/JSONObject)

      一.之前抛异常是将json库改成了fastjson解决的,参见: http://www.cnblogs.com/gossip/p/5369670.html     异常信息:     二.解决步骤 ...

  4. Java设计模式-装饰模式(Decorator)

    顾名思义,装饰模式就是给一个对象增加一些新的功能,而且是动态的,要求装饰对象和被装饰对象实现同一个接口,装饰对象持有被装饰对象的实例,关系图如下: Source类是被装饰类,Decorator类是一个 ...

  5. bootstrap table简洁扁平的表格

    使用方法 1.在html页面的head标签中引入Bootstrap库(假如你的项目还没使用)和bootstrap-table.css. <link rel="stylesheet&qu ...

  6. 【ZOJ 3870】 Team Formation

    题意 n个数,找出有几对a.b 符合 a ^ b > max(a,b) .^表示异或号 分析 对于数a,如果它的二进制是: 1 0 1  0 0 1,那么和它 ^ 后 能比他大的数就是: 0 1 ...

  7. BZOJ-1001 狼抓兔子 (最小割-最大流)平面图转对偶图+SPFA

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MB Submit: 14686 Solved: 3513 [Submit][ ...

  8. 【poj3714】 Raid

    http://poj.org/problem?id=3714 (题目链接) 现在才搞平面最近点对..感觉有点尴尬 题意 给出平面上两组点,每组n个,求两组点之间最短距离 Solution1 平面最近点 ...

  9. POJ2437 Muddy roads

    Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...

  10. Pseudo-elements ::before, ::after 範例

    xhtml <strong class="amount">700</strong> css .amount::before {content:"$ ...