hdu-2955(01背包+逆向思维+审题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955
思路:注意p和m[i]是被抓的概率,不能直接用,要转换为逃跑的概率,然后将得到的钱视为背包体积再求解。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
double p,vol[],dp[];
int n,t,cost[];
int main(void)
{
int i,j,sum;
cin>>t;
while(t--)
{
memset(dp,,sizeof(dp));
sum=;
dp[]=;
cin>>p>>n;
p=1.0-p;
for(i=;i<n;i++) cin>>cost[i]>>vol[i],sum+=cost[i],vol[i]=1.0-vol[i];
for(i=;i<n;i++)
{
for(j=sum;j>=cost[i];j--)
dp[j]=max(dp[j],dp[j-cost[i]]*vol[i]);
}
for(i=sum;i>=;i--)
{
if(dp[i]>=p) break;
}
cout<<i<<endl;
}
return ;
}
hdu-2955(01背包+逆向思维+审题)的更多相关文章
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
- HDU 2955 01背包(思维)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Robberies hdu 2955 01背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 1203 01背包 I need a offer
hdu 1203 01背包 I need a offer 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 题目大意:给你每个学校得到offe ...
- HDU 1864 最大报销额(01背包,烂题)
题意:被坑惨,单项不能超过600,其实是一张发票上A类/B类/C类的总和分别不能超过600. 思路:此题的数据很烂.用贪心也能过,用01背包也可以.都测试不出到底那些是错的. #include < ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
题目链接: id=3211">poj3211 hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...
- hdu 1864 01背包 最大报销额
http://acm.hdu.edu.cn/showproblem.php?pid=1864 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...
- BZOJ-1625 宝石手镯 01背包(傻逼题)
傻逼题,懒得打,复制蛋蛋的.. 1625: [Usaco2007 Dec]宝石手镯 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1076 Solved: ...
随机推荐
- NDK开发中的一个HTTP下载实例附带下载进度
有一个控制下载的管理类吧,调用http下载类进行各种下载,同时在下载过程中可以显示其下载的进度,而且在每个下载结束之后以类似回调的方式告诉管理类,以继续进行后续的操作. 直接代码: .h文件 #pra ...
- SpringMVC post和get乱码解决方式
如何解决POST请求中文乱码问题,GET的又如何处理呢? 在web.xml中加入: <filter> <filter-name>CharacterEncodingFil ...
- SOA和微服务到底是什么关系
本文原创,原文地址为:http://www.cnblogs.com/fengzheng/p/5847441.html SOA和微服务到底是什么关系? 说实话,我确实不明白SOA和微服务到底有什么本质上 ...
- Haskell语言学习笔记(52)正则表达式
Text.Regex.PCRE.Heavy $ brew install pcre $ cabal install pcre-heavy Installed pcre-heavy-1.0.0.2 Pr ...
- commonCookie.js
/** * Created with JetBrains WebStorm. * NAME: commonCookie.js */(function(window,document){ var com ...
- ubuntu安装openssh-server 报依赖错误的解决过程
ubuntu自带的有openssh-client,所以可以通过 ? 1 ssh username@host 来远程连接linux 可是要想通过ssh被连接,ubuntu系统需要有openssh-ser ...
- RedisTemplate Redis 操作
stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);//向r ...
- padding-top和margin-top的区别
学习前端知识,对我们查找页面元素很有帮助,而且自己在原公司时,有参与一个QA系统,自己去设计了这个产品,出了原型图,同时设计了几个页面,希望通过做这个产品提高自己的技术,可是因为离职,所以计划搁浅了, ...
- php71 gdnz
更新yum库:yum updat yum install epel-release yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel ...
- 121. Best Time to Buy and Sell Stock (Array;DP)
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...