DP入门---Robberies
Description
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
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
Output
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
Sample Output
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
double dp[];
int main()
{
int T,N,sum,money[];
double P,p[];
scanf("%d",&T);
while(T--)
{
sum=;
scanf("%lf%d",&P,&N);
P=-P;
for(int i=; i<N; i++)
{
int d;
double f;
scanf("%d%lf",&d,&f);
money[i]=d;
p[i]=-f;
sum+=d;
}
memset(dp,,sizeof(dp));
dp[]=;
for(int i=; i<N; i++)
for(int j=sum; j>=money[i]; j--)
{
dp[j]=max(dp[j],dp[j-money[i]]*p[i]);
}
for(int i=sum;i>=;i--)
if(dp[i]>=P)
{
printf("%d\n",i);
break;
}
}
return ;
}
DP入门---Robberies的更多相关文章
- poj 3254 状压dp入门题
1.poj 3254 Corn Fields 状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...
- xbz分组题B 吉利数字 数位dp入门
B吉利数字时限:1s [题目描述]算卦大湿biboyouyun最近得出一个神奇的结论,如果一个数字,它的各个数位相加能够被10整除,则称它为吉利数.现在叫你计算某个区间内有多少个吉利数字. [输入]第 ...
- 【dp入门题】【跟着14练dp吧...囧】
A HDU_2048 数塔 dp入门题——数塔问题:求路径的最大和: 状态方程: dp[i][j] = max(dp[i+1][j], dp[i+1][j+1])+a[i][j];dp[n][j] = ...
- 数位dp入门 hdu2089 不要62
数位dp入门 hdu2089 不要62 题意: 给定一个区间[n,m] (0< n ≤ m<1000000),找出不含4和'62'的数的个数 (ps:开始以为直接暴力可以..貌似可以,但是 ...
- POJ 2342 树形DP入门题
有一个大学的庆典晚会,想邀请一些在大学任职的人来參加,每一个人有自己的搞笑值,可是如今遇到一个问题就是假设两个人之间有直接的上下级关系,那么他们中仅仅能有一个来參加,求请来一部分人之后,搞笑值的最大是 ...
- hdu3555 Bomb 数位DP入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...
- 【专章】dp入门
动态规划(简称dp),可以说是各种程序设计中遇到的第一个坎吧,这篇博文是我对dp的一点点理解,希望可以帮助更多人dp入门. ***实践是检验真理的唯一标准,看再多文章不如自己动手做几道!!!*** 先 ...
- HDU 2084 数塔(简单DP入门)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- 树形dp 入门
今天学了树形dp,发现树形dp就是入门难一些,于是好心的我便立志要发一篇树形dp入门的博客了. 树形dp的概念什么的,相信大家都已经明白,这里就不再多说.直接上例题. 一.常规树形DP P1352 没 ...
随机推荐
- c#如何区分静态只读变量和常量
常量const 常量就是一个其值永远不会改变的静态字段.常量的值会在编译时自动推算,编译器会在遇到常量时,将其逐个替换为该常量的值.常量可以是C#内建的任何数字类型或枚举类型.声明一个常量的时候必须对 ...
- MT写的对URL操作的两个方法
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- WPF自定义控件
一.ImageButton 1.继承ImageButtonButton,添加依赖属性 using System; using System.Windows; using System.Windows. ...
- 【Android】Kill Service
花了一天时间对如何Android保证Service不被杀死研究了一下,我的手机是Nexus5,系统4.4.2. 杀死一个Service通常有以下几种可能: 1)APP自己杀死(包括调用stopServ ...
- ASP.NET服务器控件使用之Reportviewer 报表
http://blog.csdn.net/oemoon/article/details/7338967 http://www.cnblogs.com/emanlee/archive/2008/09/1 ...
- NGUI 修改Shader支持灰色滤镜
之前有人做过,不过效率不高: http://blog.csdn.net/onerain88/article/details/12197277 他的代码: fixed4 frag (v2f i) : ...
- Hibernate基础映射
在说Hibernate映射前,我们先来了解下对象关系映射 ORM.ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现.这样开发人员就可以把对数据库的操作转化为对这些对象的操作.我们 ...
- [Design Patterns] 1. Primary concept & term - UML
It's time to review design patterns, especially when I reach the turning-point of my career. That's ...
- Character Controller (角色控制器) 中 Move()和SimpleMove() 的区别
首先给出两者的圣典: CollisionFlagsMove(Vector3motion); Description A more complex move function taking absolu ...
- 链表中倒数第k个结点
题目: 输入一个链表,输出该链表中倒数第k个结点. 思路: 因为是单向链表,如果使用最普通的遍历来解决的话会多出很多不必要的遍历.有一个比较好的解法,设置两个指针两个指针之间差k-1个位置,也就是当后 ...