HDU 2955(0-1背包问题)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/M
题目:
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<cstring>
using namespace std;
double q[],f[];
int m[];
double max(double a,double b)
{
if(a>b) return a;
else return b;
}
int main()
{
int t,n,i,j,M;
double p;
cin>>t;
while(t--)
{
M=;
memset(f,,sizeof(f));
cin>>p>>n;
for(i=;i<=n;i++)
{
cin>>m[i]>>q[i];
M=M+m[i];
}
f[]=;
for(i=;i<=n;i++)
for(j=M;j>=m[i];j--)
f[j]=max(f[j],f[j-m[i]]*(-q[i]));
for(i=M;i>=;i--)
{
if(f[i]>=-p)
{
cout<<i<<endl;
break;
}
}
}
return ;
}
HDU 2955(0-1背包问题)的更多相关文章
- HDU 2955(01背包问题)
M - 01背包 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descript ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 4370 0 or 1 (最短路+最小环)
0 or 1 题目链接: Rhttp://acm.hust.edu.cn/vjudge/contest/122685#problem/R Description Given a n*n matrix ...
- 蓝桥杯 0/1背包问题 (java)
今天第一次接触了0/1背包问题,总结一下,方便以后修改.不对的地方还请大家不啬赐教! 上一个蓝桥杯的例题: 数据规模和约定 代码: import java.util.Scanner; public ...
- HDU - 4370 0 or 1
0 or 1 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- 经典递归问题:0,1背包问题 kmp 用遗传算法来解背包问题,hash表,位图法搜索,最长公共子序列
0,1背包问题:我写笔记风格就是想到哪里写哪里,有很多是旧的也没删除,代码内部可能有很多重复的东西,但是保证能运行出最后效果 '''学点高大上的遗传算法''' '''首先是Np问题的定义: npc:多 ...
- Java实现动态规划法求解0/1背包问题
摘要: 使用动态规划法求解0/1背包问题. 难度: 初级 0/1背包问题的动态规划法求解,前人之述备矣,这里所做的工作,不过是自己根据理解实现了一遍,主要目的还是锻炼思维和编程能力,同时,也是为了增进 ...
- Hdu 2955 Robberies 0/1背包
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 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
随机推荐
- WPF中查看PDF文件
需要打开PDF文件时,我们第一印象就是使用Adobe Reader.在开发中,经常会遇到需要展示PDF文件的需求.我们会借助于Adobe Reader的Active控件来实现.不过这需要客户的机器上安 ...
- hdu 2232 矩阵 ***
一天四个不同的机器人a.b.c和d在一张跳舞毯上跳舞,这是一张特殊的跳舞毯,他由4个正方形毯子组成一个大的正方形毯子,一开始四个机器人分别站在4 块毯子上,舞蹈的每一步机器人可以往临近(两个毯子拥有同 ...
- 总结列表显示ListView知识点
全选ListView的item条目 单选ListView的条目 多选ListView的item条目 自定义ArrayAdapter动态改变ListView的不同item样式 动态增加和删除ListVi ...
- C# 对象转换为byte[] ,byte[]还原对象
/// <summary> /// 将一个object对象序列化,返回一个byte[] /// </summary> /// <param name ...
- Android adb的使用
参考:http://blog.csdn.net/veryitman/article/details/6437090 1. 进入shell 进入设备shell adb shell 2. 安装 apk & ...
- POJ 3140 Contestants Division 树形DP
Contestants Division Description In the new ACM-ICPC Regional Contest, a special monitoring and su ...
- Eclipse的详细安装步骤
第一种:这个方法是在线安装的 第二种:下载完整免安装包 首先打开网址:http://www.eclipse.org/ 然后在这里我就选择64位的安装,就以安装安卓开发的举例: 然后下载即可:
- MySQL的中文编码问题
创建表格时,怎么让表格显示中文?注意:不区分大小写 mysql> ALTER TABLE 表格的名字 CONVERT TO CHARACTER SET UTF8; 怎么让默认的数据库支持中文字符 ...
- SpringRMI解析3-RmiServiceExporter逻辑细节
在发布RMI服务的流程中,有几个步骤可能是我们比较关心的. 获取registry 由于底层的封装,获取Registry实例是非常简单的,只需要使用一个函数LocateRegistry.createRe ...
- 常用函数的DTFT变换对和z变换对
直接从书上抓图的,为以后查表方便 1.DTFT 2.z变换对