hdu2955(变形01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955
分析:被抓概率可以转换成安全概率,Roy的安全概率大于1-P时都是安全的。
抢劫的金额为0时,肯定是安全的,所以dp[0]=1;其他金额初始为最危险的所以概率全为0;
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- #include <cstdlib>
- #include <vector>
- #include <set>
- #include <map>
- #define LL long long
- #define inf 1<<30
- using namespace std;
- int c[];
- int n;
- double p,dp[],w[];
- int main()
- {
- int T;
- scanf("%d",&T);
- while(T--)
- {
- scanf("%lf%d",&p,&n);p=-p;
- int sum=;
- for(int i=;i<=n;i++)
- {
- scanf("%d%lf",&c[i],&w[i]);
- sum+=c[i];w[i]=-w[i];
- }
- memset(dp,,sizeof(dp));
- dp[]=;
- for(int i=;i<=n;i++)
- for(int j=sum;j>=c[i];j--)
- dp[j]=max(dp[j],dp[j-c[i]]*w[i]);
- for(int i=sum;i>=;i--)
- if(dp[i]>p)
- {
- printf("%d\n",i);
- break;
- }
- }
- }
hdu2955(变形01背包)的更多相关文章
- Robberies(HDU2955):01背包+概率转换问题(思维转换)
Robberies HDU2955 因为题目涉及求浮点数的计算:则不能从正面使用01背包求解... 为了能够使用01背包!从唯一的整数(抢到的钱下手)... 之后就是概率的问题: 题目只是给出被抓的 ...
- E - 梦幻岛宝珠 HYSBZ - 1190 变形01背包 难
E - 梦幻岛宝珠 HYSBZ - 1190 这个题目我觉得很难,看题解都看了很久. 首先可以得到一个大概的思路就是分组,每一个数都可以分成 a*2^b 所以把b相同的数都分成一个组. 在每一组内部 ...
- HDU2955 Robberies[01背包]
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu-2955(01背包+逆向思维+审题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:注意p和m[i]是被抓的概率,不能直接用,要转换为逃跑的概率,然后将得到的钱视为背包体积再 ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- UVA 562 Dividing coins --01背包的变形
01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostre ...
- FZU 2214 Knapsack problem 01背包变形
题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大, ...
- codeforce Gym 101102A Coins (01背包变形)
01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstri ...
- HDU 2639 Bone Collector II(01背包变形【第K大最优解】)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- 11586 - Train Tracks
Problem J: Train Tracks Andy loves his set of wooden trains and railroad tracks. Each day, Daddy has ...
- Paip.断点调试MYSQL存储过程跟函数的解决方案大法
Paip.断点调试MYSQL存储过程跟函数的解决方案大法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn ...
- Javascript/Jquery——简单定时器
第一种方法: <%@ page language="java" contentType="text/html; charset=UTF-8"pageEnc ...
- ANTLR4权威參考手冊(一)
写在前面的话: 此文档是对伟大的Terence Parr的著作<the definitive antlr4 reference>的翻译本.致敬!欢迎转载,请注明原地址,请尊重劳动成果.翻译 ...
- LeetCode77:Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 - n. For example, ...
- 大豆生物柴油驱动的大巴斯(Bus)
请看下图: 这是大豆生物柴油(Soybean biodiesel)驱动的大巴斯(Bus)的外观,感觉非常有劲. 回想历史,1893年,德国学者Rudolf Diesel(1858-1913)发明了一种 ...
- POJ2782:Bin Packing
Description A set of n<tex2html_verbatim_mark> 1-dimensional items have to be packed in iden ...
- java中完美打包
前言: 我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: ecl ...
- 在tornado中使用celery实现异步任务处理之中的一个
一.简单介绍 tornado-celery是用于Tornado web框架的非堵塞 celeryclient. 通过tornado-celery能够将耗时任务增加到任务队列中处理, 在celery中创 ...
- Python 学习入门(23)—— 进程
本文介绍Python的os包中有查询和修改进程信息的函数,Python的这些工具符合Linux系统的相关概念,所以可以帮助理解Linux体系. 1. 进程信息 os包中相关函数如下: uname() ...