Little Tiger vs. Deep Monkey

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 2670    Accepted Submission(s): 921

Problem Description
A crowd of little animals is visiting a mysterious laboratory – The Deep Lab of SYSU.

“Are
you surprised by the STS (speech to speech) technology of Microsoft
Research and the cat face recognition project of Google and academia?
Are you curious about what technology is behind those fantastic demos?”
asks the director of the Deep Lab. “Deep learning, deep learning!”
Little Tiger raises his hand briskly. “Yes, clever boy, that’s deep
learning (深度学习/深度神经网络)”, says the director. “However, they are only ‘a
piece of cake’. I won’t tell you a top secret that our lab has invented a
Deep Monkey (深猴) with more advanced technology. And that guy is as
smart as human!”

“Nani ?!” Little Tiger doubts about that as he
is the smartest kid in his kindergarten; even so, he is not as smart as
human, “how can a monkey be smarter than me? I will challenge him.”

To
verify their research achievement, the researchers of the Deep Lab are
going to host an intelligence test for Little Tiger and Deep Monkey.

The
test is composed of N binary choice questions. And different questions
may have different scores according to their difficulties. One can get
the corresponding score for a question if he chooses the correct answer;
otherwise, he gets nothing. The overall score is counted as the sum of
scores one gets from each question. The one with a larger overall score
wins; tie happens when they get the same score.

Little Tiger
assumes that Deep Monkey will choose the answer randomly as he doesn’t
believe the monkey is smart. Now, Little Tiger is wondering “what score
should I get at least so that I will not lose in the contest with
probability of at least P? ”. As little tiger is a really smart guy, he
can evaluate the answer quickly.

You, Deep Monkey, can you work it out? Show your power!�

 
Input
The first line of input contains a single integer T (1 ≤ T ≤ 10) indicating the number of test cases. Then T test cases follow.

Each
test case is composed of two lines. The first line has two numbers N
and P separated by a blank. N is an integer, satisfying 1 ≤ N ≤ 40. P is
a floating number with at most 3 digits after the decimal point, and is
in the range of [0, 1]. The second line has N numbers separated by
blanks, which are the scores of each question. The score of each
questions is an integer and in the range of [1, 1000]�

 
Output
For each test case, output only a single line with the answer.
 
Sample Input
1
3 0.5
1 2 3
 
Sample Output
3
 
Source
 
一直没做过概率dp竟有些zz了,搞好久才看懂胜负的概率都是1/2,dp[i][j]表示处理前i件题目得到j分的概率,
那么有  dp[i][j]+=dp[i-1][j-a[i]]*0.5       j>=a[i];
             dp[i][j]+=dp[i-1][j]*0.5;
这两个式子分别表明了买和不买第i件物品得到j分的概率,加在一起就是前i件物品获得j分的概率了,加法和乘法定律要搞清楚。
这里我用了滚动数组优化,注意概率不同于价值,即使不买也会有一定的概率得到,所以j要循环到0;
 #include<bits/stdc++.h>
using namespace std;
#define eps 1e-8
double dp[];
int main()
{
int n,m,i,j,t,k;
int a[];
double P;
cin>>t;
while(t--){int s=;cin>>n>>P;
memset(dp,,sizeof(dp)); dp[]=1.0;
for(i=;i<=n;++i) cin>>a[i],s+=a[i];
for(i=;i<=n;++i){
for(j=s;j>=;--j){
dp[j]=dp[j]/;
if(j>=a[i]) dp[j]+=dp[j-a[i]]/;
}
}
double x=;
for(i=;i<=s;++i){
x+=dp[i];
if(x>=P||(fabs(x-P)<=eps)){cout<<i<<endl;break;}
}
}
return ;
}
 
 

HDU 4815 概率dp,背包的更多相关文章

  1. HDU 4599 概率DP

    先推出F(n)的公式: 设dp[i]为已经投出连续i个相同的点数平均还要都多少次才能到达目标状态. 则有递推式dp[i] = 1/6*(1+dp[i+1]) + 5/6*(1+dp[1]).考虑当前这 ...

  2. HDU 5001 概率DP || 记忆化搜索

    2014 ACM/ICPC Asia Regional Anshan Online 给N个点,M条边组成的图,每一步能够从一个点走到相邻任一点,概率同样,问D步后没走到过每一个点的概率 概率DP  測 ...

  3. hdu 3853 概率dp

    题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...

  4. hdu 4050(概率dp)

    算是挺简单的一道概率dp了,如果做了前面的聪聪于可可的话,这题不需要什么预处理,直接概率dp就行了... #include <stdio.h> #include <stdlib.h& ...

  5. hdu 1203 概率+01背包

    I NEED A OFFER! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  6. HDU 4405 (概率DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 题目大意:飞行棋.如果格子不是飞行点,扔骰子前进.否则直接飞到目标点.每个格子是唯一的飞行起点 ...

  7. HDU 4003 (树形DP+背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4003 题目大意:有K个机器人,走完树上的全部路径,每条路径有个消费.对于一个点,机器人可以出去再回来 ...

  8. HDU 1561 (树形DP+背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1561 题目大意:从树根开始取点.最多取m个点,问最大价值. 解题思路: cost=1的树形背包. 有 ...

  9. HDU 1011 (树形DP+背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1011 题目大意:树上取点,先取父亲,再取儿子.每个点,权为w,花费为cost,给定m消费总额,求最大 ...

随机推荐

  1. debian 如何切换为root用户

    debian 如何切换为root用户   debian 如何切换为root用户 sudo su 输入命令后提示输入密码,输入密码切换为root用户

  2. vue Element-ui 表格自带筛选框自定义高度

    el-table中可以在一行的某列进行筛选,代码如下: <el-table-column prop="classOfTest" class="test" ...

  3. idea操作数据库

    1.View-->>Tool Windows-->>Database. 2.点击“+”号-->>选择Data Source-->>选择需要连接的数据库类 ...

  4. 安装和使用php的mcrypt扩展

    程序员们在编写代码程序时,除了要保证代码的高性能之外,还有一点是非常重要的,那就是程序的安全性保障.PHP除了自带的几种加密函数外,还有功能更全面的PHP加密扩展库和. 其中,Mcrypt扩展库可以实 ...

  5. C++之旅(第一天)

    基础知识 完全支持C语言 可以在C++引入C的头文件 #include <stdio.h> #include <iostream> int main() { } 输入和输出 C ...

  6. $一步一步学Matlab(4)——使用Matlab进行初等数学运算

    Matlab可以看成是一个功能强大的计算器,那么既然是计算器,进行基本的数学运算绝对是必不可少的.本文主要讲解如何用Matlab做初等数学运算,所谓"初等数学运算",可以理解成是小 ...

  7. laravel request 增加字段

    https://segmentfault.com/q/1010000006898668 $input = $request->only(['username', 'password']); // ...

  8. 【Python】装饰器 & 偏函数

    [装饰器] 1.最简单的Decorator. def author(f): def addName(): print('My name is xkfx.\n') f() return addName ...

  9. CSS Link(链接)

    CSS Link(链接) 不同的链接可以有不同的样式. 一.链接样式 链接的样式,可以用任何CSS属性(如颜色,字体,背景等). 特别的链接,可以有不同的样式,这取决于他们是什么状态. 这四个链接状态 ...

  10. 20145301实验五 Java网络编程及安全

    北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1453 指导教师:娄嘉鹏 实验日期:2016.05.06 18:30-21:30 实验名称:实验五 Java网络编程 实验内容 ...