题意:

哈利波特抢银行。。。

给出n个银行,每个银行有a[i]百万和b[i]的风险。然后再给一个风险值P,不能超过P。

思路:

如果告诉你概率的小数的位数,可能这个就会不一样了。。。

慨率的计算,风险最低和被捕概率;

dp[i][j] 为 前i个抢j元的最小被捕概率。

这里可以直接一维做,其实背包很多前i个物品这样子的都可以弄成1维的。因为处理完每次要用的就是i-1的状态,前i-1直接好像貌似就是报废了。。。。

#include<bits/stdc++.h>
//#include<cstdio>
//#include<math.h>
//#include<string.h>
//#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double eps=1e-5;
const double pi=acos(-1.0);
const int mod=1e8+7;
const LL INF=0x3f3f3f3f; const int N=1e4;
double dp[N+50]; int main()
{
int x;
double y,p;
int cas=1;
int t,i,k,j,n;
scanf("%d",&t);
while(t--)
{
for(i=0;i<=N;i++)
dp[i]=-1;
dp[0]=0;
scanf("%lf%d",&p,&n);
for(i=1;i<=n;i++){
scanf("%d%lf",&x,&y);
for(j=N;j>=x;j--){
if(dp[j-x]==-1)
continue;
if(dp[j]==-1)
dp[j]=dp[j-x]+(1.0-dp[j-x])*y;
else
dp[j]=min(dp[j],dp[j-x]+(1.0-dp[j-x])*y);
}
}
int ans = 0;
for(int i=0;i<=N;i++)
if(dp[i]!=-1&&dp[i]<=p)
ans=i;
printf("Case %d: %d\n",cas++,ans);
}
return 0;
}

lightoj1079【背包】的更多相关文章

  1. LightOJ - 1079 Just another Robbery —— 概率、背包

    题目链接:https://vjudge.net/problem/LightOJ-1079 1079 - Just another Robbery    PDF (English) Statistics ...

  2. LightOJ-1079-Just another Robbery(概率, 背包)

    链接: https://vjudge.net/problem/LightOJ-1079#author=feng990608 题意: As Harry Potter series is over, Ha ...

  3. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

  4. HDU 3535 AreYouBusy (混合背包)

    题意:给你n组物品和自己有的价值s,每组有l个物品和有一种类型: 0:此组中最少选择一个 1:此组中最多选择一个 2:此组随便选 每种物品有两个值:是需要价值ci,可获得乐趣gi 问在满足条件的情况下 ...

  5. HDU2159 二维完全背包

    FATE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. CF2.D 并查集+背包

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit p ...

  7. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  8. 洛谷P1782 旅行商的背包[多重背包]

    题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能 ...

  9. POJ1717 Dominoes[背包DP]

    Dominoes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6731   Accepted: 2234 Descript ...

随机推荐

  1. stl_内存基本处理工具

    内存基本处理工具 STL定义5个全局函数.作用于初始化空间上.各自是:用于构造的construct(),用于析构的destroy(),uninitialized_copy(),uninitialize ...

  2. [LeetCode][Java] Longest Common Prefix

    题目: Write a function to find the longest common prefix string amongst an array of strings. 题意: 写出一个函 ...

  3. SQL Server故障转移集群

    在XenServer集群上给客户搭建一个应用服务,要求有负载均衡,Web服务器用Windows Server 2008 R2 + IIS,数据库Sql Server 2008 R2,并且使用SAN存储 ...

  4. 【python】How to change the Jupyter start-up folder

    Copy the Jupyter Notebook launcher from the menu to the desktop. Right click on the new launcher and ...

  5. 翻译:A Tutorial on the Device Tree (Zynq) -- Part IV

    获取资源信息 内核模块驱动加载之后,就开始把硬件资源管理起来,如读写寄存器.接收中断. 来看看设备树里的一条: xillybus_0: xillybus@50000000 { compatible = ...

  6. 项目Beta冲刺(团队1/7)

    项目Beta冲刺(团队1/7) 团队名称: 云打印 作业要求: 项目Beta冲刺(团队) 作业目标: 完成项目Beta版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 陈宇 ...

  7. Monkey测试的参数

    一.Monkey测试简介 Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动Trackball.按键等操作来对设备上的程序进行压 力测试,检测程序多久 ...

  8. 浅谈JavaScript的事件(事件对象)

    在触发DOM上的某个事件时,会产生一个事件对象event,这个对象中包含这所有与事件有关的信息.包括导致事件的元素.事件的类型和事件的相关信息.例如鼠标操作的事件中,会包含鼠标的位置信息.而键盘触发的 ...

  9. 在Windows上使用libcurl发起HTTP请求

    curl下载地址https://curl.haxx.se/download.html 当前最新版本为7.61.0 将下载的curl-7.61.0.zip解压,得到curl-7.61.0 在目录curl ...

  10. ruby 学习网站

    Ruby on Rails官网: http://rubyonrails.org/ Rails Guides:http://guides.rubyonrails.org/ -中文版: http://gu ...