http://acm.hdu.edu.cn/showproblem.php?pid=4815

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!�/div>

 

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]�/div>

 

Output

For each test case, output only a single line with the answer.
 

Sample Input

 
3 0.5
1 2 3
 

Sample Output

3
 
 
 
题目大意:n道题。每道题有一定的分值(如果答对一道题就会获得相应的分数,答错该题则没分),两个
人来答题A随机答题,问B最少得拿多少分才能保证有p的概率不会输(即有1-p的概率会赢)
 
01背包问题,dp[i][j]表示答i道题共得j分的概率,那么答第i+1答题有两种情况,有可能答对也有可能答错,各占0.5
1.第i+1答题答对,则得分概率为的dp[i+1][j+a[i]] ;(a[i]表示第i+1道题的分数,因为i是从0开始)
2.第i+1答题答错,则得分概率为的dp[i+1][j];
统计道n道题的各种得分情况概率之和x,然后当x满足条件x>1-p时便可输出此时得分;
 
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std; const int N = ;
const int M = ; int a[N];
double dp[N][M]; int main()
{
int t, n;
double p;
scanf("%d", &t);
while(t--)
{
scanf("%d%lf", &n, &p);
for(int i = ; i < n ; i++)
scanf("%d", &a[i]);
memset(dp, , sizeof(dp));
dp[][] = ;//写0道题得0分的概率为1
for(int i = ; i < n ; i++)
{
for(int j = ; j < n * ; j++)
{
dp[i + ][j] += dp[i][j] * 0.5;//第i+1道题没有写对,没有拿到这道题的分
dp[i + ][j + a[i]] += dp[i][j] * 0.5;//第i+1道题写对了,拿到了这道题的分
}
}
double x = ;
int m = ;
for(int j = n * ; j >= ; j--)
{
x += dp[n][j];//写n道题各个得分的概率和
if(x > - p)
{
m = j;
break;
}
}
printf("%d\n", m);
}
return ;
}

hdu 4815 Little Tiger vs. Deep Monkey(01背包)的更多相关文章

  1. HDU4815 Little Tiger vs. Deep Monkey——0-1背包

    题目描述 对于n道题目,每道题目有一个分值,答对加分,答错不得分,你要和一个叫深猴的比赛,题目你可以假设成判断题(不是对就是错),深猴对于所有的题目都是随机选择一个答案,而你是有脑子的,求为了不输掉比 ...

  2. HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 简单的DP题. #include <stdio.h> #include <st ...

  3. HDU 4815 Little Tiger vs. Deep Monkey 2013 长春现场赛C题

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 [题意] n个题目,每题有各自的分数,A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率 ...

  4. hdu 4815 Little Tiger vs. Deep Monkey

    概率dp,有点像背包的做法: dp[i][j]代表前i个数组成的j数的概率为多少 #include<cstdio> #include<cstring> #define maxn ...

  5. HDU - 4815 Little Tiger vs. Deep Monkey (长春赛区C题)

    题意:有A,B两个人.n道题目.每题有相应的分数.B答对题目的概率是0.5.求A不输给B的概率不小于P要拿的最低分数 思路:DP,dp[i][j]来表示B答了前i题后分数为j的概率,,然后通过B的概率 ...

  6. hdu 2126 Buy the souvenirs 二维01背包方案总数

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. HDU 1203 I NEED A OFFER!(01 背包DP)

    点我看题目 题意 : 中文题不详述. 思路 :类似于01背包的DP,就是放与不放的问题,不过这个要求概率,至少得到一份offer的反面就是一份也得不到,所以先求一份也得不到的概率,用1减掉就可以得到所 ...

  8. HDU 5887 Herbs Gathering(搜索求01背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=5887 题意: 容量很大的01背包. 思路: 因为这道题目背包容量比较大,所以用dp是行不通的.所以得用搜索来做, ...

  9. HDU 3339 In Action【最短路+01背包】

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Other ...

随机推荐

  1. Open Explorer Plugin for Eclipse (eclipse 插件 在eclipse里面打开文件目录)

    就是在eclipse里面直接打开文件所在的目录地址 只要将下面的jar 文件放到你的 “$ECLIPSE_HOME/plugins”  下面,重启eclipse就ok了 要想卸载的话  停止eclip ...

  2. [转] Qt 多线程学习

    Qt 多线程学习 转自:http://www.cnblogs.com/IT-BOY/p/3544220.html 最近的项目上用到了关于多线程的知识,自己也比较感兴趣,所以就拿了那本<C++ G ...

  3. fmri分析工具:spm里的统计学 Introduction to SPM statistics

     引言 Introduction 需要特别说明,spm是每一个体素为单位,计算统计量,进行t检验. 1.分别在每个体素上做方差分析; 2.对每个体素的方差分析结果,计算t检验统计量; 3.计算等同于t ...

  4. PHP实现站点pv,uv统计(一)

    具体步骤分为数据采集脚本,数据收取服务,数据分析脚本,数据存储服务 采集脚本一般有两种形式,一种是简单的页面插入一个图片进行请求,一种是复杂的动态生成js标签,引入一段js(这时采集服务器会网往客户端 ...

  5. HDU 3183 A Magic Lamp

    直接模拟   如果后一位比前一位小,那就一直 向前 pop()掉 维护他单调递增: #include<iostream> #include<cstring> #include& ...

  6. 【NYOJ-35】表达式求值——简单栈练习

    表达式求值 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min ...

  7. 自己的一个LESS工具函数库

    自己大概在一年前开始使用LESS编写样式,现在感觉不用LESS都不会写样式了.现在写静态页面完全离不开LESS与Zen Coding,我可以不用什么IDE,但这两个工具却必须要,当然也强烈推荐看到这篇 ...

  8. Docker 基础技术:Linux Namespace(下)

    导读 在Docker基础技术:Linux Namespace(上篇)中我们了解了,UTD.IPC.PID.Mount 四个namespace,我们模仿Docker做了一个相当相当山寨的镜像.在这一篇中 ...

  9. [转载]C++异常机制的实现方式和开销分析

    原文章网址:http://baiy.cn/doc/cpp/inside_exception.htm C++异常机制的实现方式和开销分析 白杨 http://baiy.cn 在我几年前开始写<C+ ...

  10. 360网站卫士推出google字体加速方案

    最近,有网友反映称谷歌官网域名google.com.谷歌香港google.com.hk都打不开, ping了一下google.com和google.com.hk两个域名的服务器情况,最后ping出来的 ...