hdu 2955 Robberies 背包DP
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12161 Accepted Submission(s): 4527
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<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<queue>
using namespace std;
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
#define MAXN 10010
#define MAXV MAXN*2
#define MAXE MAXV*2
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef long long qword;
inline int nextInt()
{
char ch;
int x=;
bool flag=false;
do
ch=getchar(),flag=(ch=='-')?true:flag;
while(ch<''||ch>'');
do x=x*+ch-'';
while (ch=getchar(),ch<='' && ch>='');
return x*(flag?-:);
}
double f[MAXN+];
int n,m;
int main()
{
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int i,j,k;
int x,y,z;
int nn;
scanf("%d",&nn);
double temp;
double plim;
double p;
int tot;
int l;
int ii;
for (ii=;ii<nn;ii++)
{
scanf("%lf %d",&temp,&n);
plim=(-temp);
int ans=;
for (i=;i<=MAXN;i++)f[i]=;
f[]=;
for (i=;i<n;i++)
{
scanf("%d %lf",&tot,&p);
p=(-p);
for (j=MAXN;j>=;j--)
{
f[j+tot]=max(f[j+tot],f[j]*p);
if (f[j+tot]>plim)ans=max(ans,j+tot);
}
}
printf("%d\n",ans);
}
return ;
}
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<queue>
using namespace std;
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
#define MAXN 100000
#define MAXV MAXN*2
#define MAXE MAXV*2
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef long long qword;
inline int nextInt()
{
char ch;
int x=;
bool flag=false;
do
ch=getchar(),flag=(ch=='-')?true:flag;
while(ch<''||ch>'');
do x=x*+ch-'';
while (ch=getchar(),ch<='' && ch>='');
return x*(flag?-:);
}
int f[MAXN+];
int n,m;
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int i,j,k;
int x,y,z;
int nn;
scanf("%d",&nn);
double temp;
int plim;
double p;
int tot;
int l;
int ii;
for (ii=;ii<nn;ii++)
{
scanf("%lf %d",&temp,&n);
plim=(-temp)*MAXN;
int ans=;
memset(f,-INF,sizeof(f));
f[MAXN]=;
for (i=;i<n;i++)
{
scanf("%d %lf",&tot,&p);
p=(-p);
for (j=plim/p;j<=MAXN;j++)
{
if (j*p<=plim)continue;
f[(int)(j*p)]=max(f[(int)(j*p)],f[j]+tot);
ans=max(ans,f[(int)(j*p)]);
}
}
printf("%d\n",ans);
}
return ;
}
hdu 2955 Robberies 背包DP的更多相关文章
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- HDU 2955 Robberies(概率DP,01背包)题解
题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱 思路:一道好像能直接01背包的题,但是有些不同.按照以往的逻辑,dp[i]都是代表i代价能拿的最高 ...
- hdu 2955 Robberies(背包DP)
题意: 小偷去抢银行,他母亲很担心. 他母亲希望他被抓的概率真不超过P.小偷打算去抢N个银行,每个银行有两个值Mi.Pi,Mi:抢第i个银行所获得的财产 Pi:抢第i个银行被抓的概率 求最多能抢得多少 ...
- 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 ...
随机推荐
- LeetCode——Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- Linux性能及调优指南(翻译)
http://blog.csdn.net/ljianhui/article/details/46718835 http://blog.chinaunix.net/uid-26000296-id-406 ...
- SOAP消息创建
看了SOAP消息分析之后,大家对soap消息应该有了一个初步的认识,那么怎样自己编写一个soap消息呢? 先来创建一个简单的soap消息: @Test public void test1(){ try ...
- iOS UIKit:TabBar Controller
1 结构剖析 IOS中的标签导航其实是一个UITabBarController对象,其也是一个Container View Controller.UITabBarController对象创建和管理了一 ...
- Unty3D动态加载图片
试验动态加载图片,代码如下: using UnityEngine; using System.Collections; public class DynamicLoad : MonoBehaviour ...
- jar打包通过exe4j转换成exe文件
去年的时候有用过,最近写java的时候偶然用到,mark一下,方便以后看 下载链接后面附上 首先我们在eclipse上打包成jar文件,我这里只把简单的截图贴出来,详细的可以自行百度 打包jar文件: ...
- 解决embed标签显示在div上层【转藏】
解决embed标签显示在div上层,非设置z-index 今天给屌炸了爆笑网增加了视频栏目,但是发现在IE8中,顶部浮动导航的div在移动到embed视频上时,总是被embed的flash文件盖住.分 ...
- PHP 进制问题
PHP有一些函数提供进制之间的转化问题 在Math函数中有一部分: decbin() - 十进制转换为二进制 bindec() — 二进制转换为十进制 octdec() - 八进制转换为十进制 hex ...
- (转)apache的keepalive和keepalivetimeout(apache优化)
KeepAlive指的是保持连接活跃,类似于Mysql的永久连接. 如果将KeepAlive设置为On,那么来自同一客户端的请求就不需要再一次连接,避免每次请求都要新建一个连接而加重服务器的负担. ...
- 解决IE无法解析json的方法
一.原始方法eval() 二.json插件--github开源插件:json-js/json2.js https://github.com/douglascrockford/JSON-js/blob/ ...