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. centos7命令3

    查看监听的端口 netstat -lntp 检查端口被哪个进程占用 netstat -lnp|grep 8080 查看当前文件夹大小 du -sh 查看当前文件夹各目录大小 du -sh ./* 查看 ...

  2. 端口状态说明 LISTENING、ESTABLISHED、TIME_WAIT及CLOSE_WAIT

    TCP状态转移要点    TCP协议规定,对于已经建立的连接,网络双方要进行四次握手才能成功断开连接,如果缺少了其中某个步骤,将会使连接处于假死状态,连接本身占用的资源不会被释放.网络服务器程序要同时 ...

  3. 【.Net基础一】 类型、对象、线程栈、托管堆运行时的相互关系

    目前在看CLR via C#,把总结的记下来,索性就把他写成一个系列吧. 1.[.Net基础一] 类型.对象.线程栈.托管堆运行时的相互关系 2.[.Net基础二]浅谈引用类型.值类型和装箱.拆箱 J ...

  4. React组件绑定this的四种方式

    题图 By HymChu From lnstagram 用react进行开发组件时,我们需要关注一下组件内部方法this的指向,react定义组件的方式有两种,一种为函数组件,一种为类组件,类组件内部 ...

  5. 前端学习笔记之ES6快速入门

    0x1 let和const let ES6新增了let命令,用于声明变量.其用法类似var,但是声明的变量只在let命令所在的代码块内有效. { let x = 10; var y = 20; } x ...

  6. mybatis v jpa

    mybatis的优势在于SQL的自由度上,SQL优化和返回对象的大小都是可控的.spring-data-JPA则在开发效率上有优势.

  7. Linux Shell脚本编程--字符串截取

    Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.aaa.com/123.htm. 1. # 号截取,删除左边字符,保留右边字符. echo ${var#*//} ...

  8. vsftpd搭建ftp服务,并实现虚拟用户访问

    安装vsftpd服务: yum install vsftpd -y [root@wadeson ~]# rpm -ql vsftpd /etc/logrotate.d/vsftpd /etc/pam. ...

  9. linux消息队列应用编程

    消息队列:  消息队列提供了一个从一个进程向另外一个进程发送一块数据的方法   每个数据块都被认为是有一个类型,接收者进程接收的数据块可以有不同的类型值   消息队列也有管道一样的不足,就是每个消息的 ...

  10. 深度学习:Keras入门(二)之卷积神经网络(CNN)【转】

    本文转载自:https://www.cnblogs.com/lc1217/p/7324935.html 说明:这篇文章需要有一些相关的基础知识,否则看起来可能比较吃力. 1.卷积与神经元 1.1 什么 ...