hdu Robberies
这道题目应该在理解上会有一点问题。这道题的概率不是用来加的,而是用来乘的。这道题要的是在能逃跑的前提下,获得的最大money,而题目中给的概率是被抓的概率,所以要先有一个预处理,之后只要列出状态转移方程就可以轻松解决了:dp[i]=max{dp[i],dp[i-v[i]]*p[i]},注意初始条件,dp[0]=1,因为若抢劫金额为0的话,那么逃跑的概率就是1.
#include"iostream"
#include"stdio.h"
#include"cmath"
#include"algorithm"
#include"string.h"
#define mx 100005
using namespace std;
double p[mx],dp[mx];
int sum[mx],v[mx];
double max(double a,double b)
{
return a>b?a:b;
}
int main()
{
int t,n,i,j;
double P;
cin>>t;
while(t--)
{
scanf("%lf%d",&P,&n);
P=-P;//最大的逃跑率
sum[]=;
for(i=;i<=n;i++)
{
cin>>v[i]>>p[i];
p[i]=-p[i];//逃跑的概率
sum[i]=sum[i-]+v[i];
}
memset(dp,0.0,sizeof(dp));
dp[]=;
for(i=;i<=n;i++)
{
for(j=sum[n];j>=v[i];j--)
{
dp[j]=max(dp[j],dp[j-v[i]]*p[i]);
}
}
for(i=sum[n];i>=;i--)
if(dp[i]>P) break;
cout<<i<<endl;
}
return ;
}
hdu Robberies的更多相关文章
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- Hdu 2955 Robberies 0/1背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- [HDU 2955]Robberies (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...
- hdu 2955 Robberies 0-1背包/概率初始化
/*Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- hdu 2955 Robberies
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 2955 Robberies 背包DP
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Robberies(HDU 2955 DP01背包)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2955 Robberies(01背包)
Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...
- HDU 2955 Robberies(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目: Problem Description The aspiring Roy the Rob ...
随机推荐
- Android runProguard配置 导致module lib 中的包编译时无法识别
今天写代码时用到了另一个lib型的工程,把它添加到dependencies后,在原工程中可以引用lib中的文件了,但是编译时就会报错,提示包不存在,后来在build.gradle中设置runProgu ...
- 手动构建Servlet项目的流程
前面讨论过手动建立jsp的项目,jsp是tomcat服务器负责编译执行,所以配置相对简单,而Servlet需要先把java源文件编译成字节码class文件,然后再执行,所以需要servlet-api. ...
- Java for LeetCode 200 Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- Codeforces 424C(异或)
Magic Formulas Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Subm ...
- min-height在安卓下不起作用
正常情况下,min-height可以当height使用 如: <div class="father"> <div class="child"& ...
- rdesktop remember
整个地球都知道rdesktop,有了它,我们可以从Solaris或者Linux使用Windows,当然Windows要开启Windows Terminal Service.虽然也有基于GTK+的tsc ...
- p235习题1
- Nginx(PHP/fastcgi)的PATH_INFO问题
引用: http://www.laruence.com/2009/11/13/1138.html server { listen 80; server_name localhost; index in ...
- Oracle如何操作级联删除
级联删除即删除包含主键值的行的操作,该值由其它表的现有行中的外键列引用.在级联删除中,还删除其外键值引用删除的主键值的所有行. 语法: Foreign Key (column[,...n]) refe ...
- ./configure会报错:pr command not found
1.2 安装coreutils 请检查${MinGWDir}/msys/1.0/bin(默认为C:/MinGW/msys/1.0/bin)下有没有pr.exe,如果没有,那么在编译libav过程 ...