HDU2955-Robberies

Robberies

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

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
 

动态规划
AC代码:

//用成功逃走的概率当做价值,银行的总钱数当做背包容量 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
   int M;//钱量
   float P;//不被抓概率
}dp[110];
float f[10010];//最大的钱量为100*100=10000;
int max(int n,int m)
{return n>m?n:m;}
int main()
{
    int i,j,T,n,m,sum;
    float x,Psum;
    scanf("%d",&T);
    while(T--)
    {
       memset(dp,0,sizeof(dp));
       memset(f,0,sizeof(f));
       scanf("%f %d",&x,&m);
       Psum=1-x;//最小逃脱率,低于这个就逃不了了
       sum=0;
       for(i=0;i<m;i++)
       {
          scanf("%d %f",&dp[i].M,&dp[i].P);
          sum+=dp[i].M;
          dp[i].P=1-dp[i].P;//逃脱率
       }

       f[0]=1;//抢0块大洋肯定不被抓

       for(i=0;i<m;i++)
       {
          for(j=sum;j>=dp[i].M;j--)
          f[j]=max(f[j],f[j-dp[i].M]*dp[i].P);//f[j]表示抢j块大洋的最大的逃脱概率,条件是f[j-q[i].money]可达,也就是之前抢劫过;
       }
       for(i=sum;i>=0;i--)
       {
          if(f[i]>=Psum)
          {break;}
       }
       printf("%d\n",i);
    }
    return 0;
}
时间: 2025-01-27 01:03:51

HDU2955-Robberies的相关文章

hdu 2955 Robberies(0/1背包)

点击打开链接hdu 2955 思路: 0/1背包 分析: 1 按照题目的意思我们很容易知道这就是一个0/1背包问题,如果我们把概率当作是背包的容量,那么我们遇到一个问题就是浮点数的dp,因为题目没有告诉我们小数点具体几位,那么我们就不能够通过乘上10^n来转化为整数,所以我们应该考虑换种思想 2 按照正常的思路是dp[i][j]表示前i个物品放入概率为j的最大价值,那么我们这边把价值当成背包来看的话我们设dp[i][j]表示前i个物品放入金钱为j的最小被抓概率(因为题目不好求最小概率我们可以认为

【DP专辑】ACM动态规划总结

转载请注明出处,谢谢.   http://blog.csdn.net/cc_again?viewmode=list          ----------  Accagain  2014年5月15日 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强,主要考察思维能力.建模抽象能力.灵活度. 本人动态规划博客地址:http://blog.csdn.net/cc_again/article/category/1261899 ******************

时间序列预测教程:如何利用 Python 预测波士顿每月持械抢劫案数量?

Jason Brownlee:时间序列预测法是一个过程,而获得良好预测结果的唯一途径是实践这个过程. 在本教程中,您将了解如何利用Python语言来预测波士顿每月持械抢劫案发生的数量. 本教程所述为您提供了一套处理时间序列预测问题的框架,包括方法步骤和工具,通过实践,可以用它来解决自己遇到的相关问题. 本教程结束之后,您将了解: 如何核查Python环境并准确地定义一个时间序列预测问题. 如何构建一套测试工具链,用于评估模型,开发预测原型.以及如何通过时间序列分析工具更好地理解你的问题. 如何开

hdu2955--01背包

1.Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955 正确的方程是:f[j]=max(f[j],f[j-q[i].money]*q[i].v) 其中,f[j]表示抢j块大洋的最大的逃脱概率,条件是f[j-q[i].money]可达,也就是之前抢劫过; 始化为:f[0]=1,其余初始化为-1 (抢0块大洋肯定不被抓嘛) #include<stdio.h> #include<string.h> double max(dou