01标题背包水章 HDU2955——Robberies
原来是dp[i],它代表的不被抓的概率i这最大的钱抢(可能1-100)
客是dp[i]表示抢了i钱最大的不被抓概率,嗯~,弱菜水题都刷不动。
那么状态转移方程就是
dp[i]=max(dp[i],dp[i-money]*p),初始化dp(0~maxn)为0,dp[0]=1(1毛钱都没抢你抓个毛线啊,哥是良民~)
又是贴代码环节~
<span style="font-size:18px;">#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
double dp[11000];
struct node
{
int m;
double p;
}a[110];
int main()
{
int T;
cin>>T;
while(T--){
double p;
int n,sum=0;
cin>>p>>n;
for(int i=0;i<n;i++){
cin>>a[i].m>>a[i].p;
a[i].p=1-a[i].p;
sum+=a[i].m;
}
memset(dp,0,sizeof dp);
dp[0]=1;
for(int i=0;i<n;i++){
for(int j=sum;j>=a[i].m;j--){
dp[j]=max(dp[j],dp[j-a[i].m]*a[i].p);
}
}
int cnt;
for(cnt=sum;cnt>=0&&1-dp[cnt]>p;cnt--);
cout<<cnt<<endl; }
return 0;
}
</span>
版权声明:本文博主原创文章,博客,未经同意不得转载。
01标题背包水章 HDU2955——Robberies的更多相关文章
- HDU2955 Robberies[01背包]
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu2955 Robberies (01背包)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=2955">http://acm.hdu.edu.cn/showproblem.php ...
- HDU-2955 Robberies 浮点数01背包 自变量和因变量位置互换
题目链接:https://cn.vjudge.net/problem/HDU-2955 题意 突然想找几个银行抢钱. 给出各银行的钱数和被抓的概率,以及能容忍的最大被抓概率. 问他最多能抢到多少钱? ...
- [Usaco2008 Dec]Hay For Sale 购买干草[01背包水题]
Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包 ...
- [Usaco2007 Dec]宝石手镯[01背包][水]
Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为 ...
- HDU 5313 Bipartite Graph(二分图染色+01背包水过)
Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...
- hdu2955 Robberies 01背包+概率
link:http://acm.hdu.edu.cn/showproblem.php?pid=2955 首先,这个题目的背包容量不能是概率.1.精度不清楚.2.把概率相加有什么意义呢?所以,转换一下, ...
- [HDU 2602]Bone Collector ( 0-1背包水题 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...
- hdu2955 Robberies(背包)
https://vjudge.net/problem/HDU-2955 概率是浮点数,只能做值(而且这里是累乘,也不能化成整数),这里注意要化成安全概率(1-p[i]),求安全概率的最大值. 钱数作二 ...
随机推荐
- sql 列轉行、行轉列
PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P ...
- ONVIF Event消息解析(How to work with gSoap)
Prepare Requirements ONVIF Event gSoap reference ONVIF Specification 问题描述 Event是ONVIF核心规范中一块, 文档解释了如 ...
- GitHub-修改以下host-ip可加快访问速度
#GitHub START 207.97.227.239 github.com 204.232.175.94 gist.github.com 107.21.116.220 help. ...
- laravel观察者模式
laravel观察者模式: 事件
- mysql操作之二
特殊数据类型 表约束 表连接 索引 触发器 安全性 DB设计 alter table student modify id int primary key; 主銉不可重复修改 alter table s ...
- USACO1.5 Checker Challenge(类n皇后问题)
B - B Time Limit:1000MS Memory Limit:16000KB 64bit IO Format:%lld & %llu Description E ...
- python处理mysql慢查询日志
# -*- coding:utf8 -*- ''' Created on 2017年1月9日 @author: qiancheng ''' import re import os from email ...
- Instruments 使用指南
Instruments 用户指南 http://cdn.cocimg.com/bbs/attachment/Fid_6/6_24457_90eabb4ed5b3863.pdf 原著:Apple Inc ...
- C语言学习--链表
#include "node.h" #include<stdio.h> #include<stdlib.h> //typedef struct _node ...
- 异步导入导出Redis数据(利用Hiredis、Libevent)
最近工作中需要用到一个将数据从Redis导出到文本(或从文本导入Redis)的工具.找到一个用Ruby写的开源软件redis-dump(http://delanotes.com/redis-dump/ ...