HDU 2955 Robberies(01背包)
Robberies
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.
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
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.
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
4
6
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
#define msd memset(dp,0,sizeof(dp))
using namespace std;
#define LOCAL
double dp[];
struct Node
{
int vo;//钱
double va;//[逃跑]概率
}v[];
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif // LOCAL
//ios::sync_with_stdio(false);
int N;
cin>>N;
while(N--)
{
double p;
int n,sum=;//sum是钱的总数,即背包容量
msd,dp[]=;//什么都不抢,逃跑率100%
scanf("%lf%d",&p,&n);
for(int i=;i<=n;i++)
{scanf("%d%lf",&v[i].vo,&v[i].va),v[i].va=-v[i].va;
sum+=v[i].vo;} for(int i=;i<=n;i++)
for(int j=sum;j>=;j--)
dp[j]=max(dp[j],dp[j-v[i].vo]*v[i].va); for(int i=sum;i>=;i--)
{
if(dp[i]>-p)
{
printf("%d\n",i);
break;
}
}
}
return ;
}
HDU 2955 Robberies(01背包)的更多相关文章
- hdu 2955 Robberies (01背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- 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(01背包变形)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 2955 Robberies (01背包好题)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU——2955 Robberies (0-1背包)
题意:有N个银行,每抢一个银行,可以获得\(v_i\)的前,但是会有\(p_i\)的概率被抓.现在要把被抓概率控制在\(P\)之下,求最多能抢到多少钱. 分析:0-1背包的变形,把重量变成了概率,因为 ...
- HDU 2955 Robberies --01背包变形
这题有些巧妙,看了别人的题解才知道做的. 因为按常规思路的话,背包容量为浮点数,,不好存储,且不能直接相加,所以换一种思路,将背包容量与价值互换,即令各银行总值为背包容量,逃跑概率(1-P)为价值,即 ...
- HDOJ 2955 Robberies (01背包)
10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem. ...
- HDU 2955 【01背包/小数/概率DP】
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDOJ.2955 Robberies (01背包+概率问题)
Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...
随机推荐
- svn用Cornerstone上传项目丢失静态库.a问题的解决
最近电脑重装系统后,装上Cornerstone上传项目后,发现又有丢失.a文件的问题,这里说一下解决办法,打开Preferences-->Subversion-->General,将Use ...
- 最近一段时间get到的小知识(c++的)
(1)查看一个程序运行的时间 int main() { clock_t start,end; start=clock(); ... end=clock(); cout<<"Run ...
- Symfony命令大全
执行命令: $ php bin/console 查看一下命令 Symfony version 3.1.5 - app/dev/debug Usage: command [options] [argum ...
- JDK根目录介绍
/bin 存放可执行程序(编译器javac.exe 运行器java.exe 文档生成器javadoc.exe等 ). /db 小型数据库文件. /jre JRE. /include 形成jdk的c. ...
- 用python做中文自然语言预处理
这篇博客根据中文自然语言预处理的步骤分成几个板块.以做LDA实验为例,在处理数据之前,会写一个类似于实验报告的东西,用来指导做实验,OK,举例: 一,实验数据预处理(python,结巴分词)1.对于爬 ...
- PHP学习资源
PHPerNote PHPerNote 是一个php程序员的工作生活笔记,本站包含了php网络编程学习教程,数据库(主要是MySQL数据库)教程,javascript,jquery,div+css,h ...
- OSI参考模型初识
纪念我曾今热爱的数通(^o^). 1.osi参考模型 2.数据的封装和解封装 3.主机和主机间通信
- 递归——CPS(一)
程序中为什么需要栈stack? 普通的程序中,接触到子程序和函数的概念,很直观地,调用子程序时,会首先停止当前做的事情,转而执行被调用的子程序,等子程序执行完成后,再捡起之前挂起的程序,这有可能会使用 ...
- 怎么 得到 DBGrid选中行的数据
转自:https://zhidao.baidu.com/question/1694035814426308148.html 一般是你鼠标点到哪一行,其DataSet的指针就指到了什么位置你可以直接通过 ...
- linux安装bind with DLZ <NIOT>
2015年6月11日 1.sudo wget ftp://ftp.isc.org/isc/bind9/9.10.1/bind-9.10.1.tar.gz 或者 使用“rz”命令 2.tar -zxv ...