[HDU 2955]Robberies (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955
题意是给你一个概率P,和N个银行
现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓
问你被抓的概率在P以下,最多能偷多少钱。
刚开始我还在想,A银行被抓的概率是a,B银行被抓的概率是b,那么偷A和B被抓的概率是a*b。。
傻逼了- -。。a*b是既被A银行抓又被B银行抓。。
所以用逃跑的概率计算
dp[i][j]代表从前i个银行里偷了j元逃跑的最大概率
代码:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAX_N = ;
const double EPS = 1e-;
double dp[MAX_N][MAX_N*MAX_N];
int T,N,m[MAX_N];
double P,p[MAX_N]; int main(){
scanf("%d",&T);
while( T-- ){
scanf("%lf%d",&P,&N);
P = - P;
int summ = ;
for(int i=;i<=N;i++){
scanf("%d%lf",&m[i],&p[i]);
p[i] = - p[i];
summ += m[i];
}
//for(int i=0;i<=summ;i++) dp[1][i] = 1;
dp[][] = ;
for(int i=;i<=N;i++){
for(int j=;j<=summ;j++){
if( j-m[i]>= ) dp[i][j] = max(dp[i-][j],dp[i-][j-m[i]]*p[i]);
else dp[i][j] = dp[i-][j];
}
}
int ans = ;
for(int i=;i<=summ;i++){
// printf("%f\n",dp[N][i]);
if( P-dp[N][i]<=EPS ){
// printf("dp[N][i]=%f < P=%f\n",dp[N][i],P);
ans = i;
}
}
// puts("");
printf("%d\n",ans);
}
return ;
} /*
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
*/
[HDU 2955]Robberies (动态规划)的更多相关文章
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 2955 Robberies(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目: Problem Description The aspiring Roy the Rob ...
- hdu 2955 Robberies (01背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- HDU 2955 Robberies(0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...
- 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 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 ...
- HDU 2955 Robberies(01背包)
Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...
随机推荐
- setOnKeyListener响应两次问题
1.Android一次按下操作定义了两个事件,ACTION_DOWN和ACTION_UP,即按下和松手两个动作. 2.除了判断是什么按键被按下,还应该判断按键是up还是down 3.调用eve ...
- Http状态码301和302概念简单区别
1.什么是301重定向? 301重定向/跳转一般,表示本网页永久性转移到另一个地址. 301是永久性转移(Permanently Moved),SEO常用的招式,会把旧页面的PR等信息转移到新页面: ...
- Eclipse设置软tab(用4个空格字符代替)及默认utf-8文件编码(unix)
简单配置版本: Eclipse設置 一.window->Preferences-> General-Editors->Text Editors , 右边勾选insert spaces ...
- 屏幕取色工具推荐 ColorPix
很好用的一个屏幕取色工具,方便套页面时,在图片上取色. 用鼠标指到取色未知,按CTRL+C,就可复制16进制的颜色值. 下载地址:http://files.cnblogs.com/zjfree/Col ...
- LintCode "Binary Representation"
Not hard to think of a solution. But the key is all details. class Solution { public: /** *@param n: ...
- 【JdbcTemplete】JdbcTemplete代码详解--模板方法详解
JdbcTemplete类层次结构 JdbcAccessor:对DataSource数据源进行管理和配置: JdbcOperations:定义了通过JDBC操作数据库的基本操作方法: JdbcTemp ...
- apidoc,一个相当不错的文档生成器
http://apidocjs.com/ 例子:myapp目录下的MyCode.java /** * * @api {get} /company/list 获取公司信息 * @apiName 获取公司 ...
- 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- IOS 日志输出控制
用以下内容可以控制在debug版本中打印日志,而在release版本中不打印 #ifdef DEBUG# define DBLog(format,...) NSLog((@"[%s][%s] ...
- (C/C++) Interview in English. - Memory Allocation/Deallocation.
Q: What is the difference between new/delete and malloc/free? A: Malloc/free do not know about const ...