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. git pull和git merge区别&&Git冲突:commit your changes or stash them before you can merge. 解决办法

    http://blog.csdn.net/sidely/article/details/40143441 原文: http://www.tech126.com/git-fetch-pull/ Git中 ...

  2. Part01、sqlalchemy 使用

    一.ORM         连表               一对多               1.创建表,主动指定外键约束.               2.操作.                 ...

  3. C# 使用 SqlBulkCopy 类批量复制数据到数据库

    最近公司需要优化导入的问题,由于之前使用的方式是生成 Insert 语句插入数据库,数据量小的时候还行,但是随着发展数据量渐渐大了,之前的方法性能就跟不上了,于是发现了 SqlBulkCopy 这个类 ...

  4. session与cookie的详解

    在PHP面试中 经常碰到请阐述session与cookie的区别与联系,以及如何修改两者的有效时间. 大家都知道,session是存储在服务器端的,cookie是存储在客户端的,session依赖于c ...

  5. Eclipse安装Activiti插件(流程设计器)

    Eclipse安装Activiti插件(流程设计器) 一.安装步骤: 1,打开Eclipse的 Help -> Install New Software,填上插件地址: Name:Activit ...

  6. 关于Log4Net的使用和配置

    1. 添加log4net.dll引用 2.在添加引用的那层的 AssemblyInfo.cs         注册   : [assembly: log4net.Config.XmlConfigura ...

  7. Vue限制输入框只能输入整数

    首先,得明确监听input输入框变化的方法是input,不是change. 方案一:type= "number" 作用: 成功禁止输入字母 能输入小数点,第一位可以为0,小数点能输 ...

  8. 学号20145303 《Java程序设计》第一周学习总结

    学号20145303 <Java程序设计>第一周学习总结 教材学习内容总结 *dos命令行: dir:列出当前目录下的文件及文件名 md:创建目录 rd:删除目录.为空时文件夹(文件夹为空 ...

  9. linux安全第一周总结——20135227黄晓妍

    实验部分: 我将源代码做了修改,将其中一个数字修改为我学号27 2.在实验楼环境下将其保存为text.c并将其编译,得到text.s 3.将.开头的多余的语句删去了之后,我得到了32位环境的汇编代码 ...

  10. 【前端】vue.js实现按钮的动态绑定

    vue.js实现按钮的动态绑定 实现效果: 实现代码以及注释: <!DOCTYPE html> <html> <head> <title>按钮绑定< ...