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. Qt之模型/视图(自定义按钮)

    简述 衍伸前面的章节,我们对QTableView实现了数据显示.自定义排序.显示复选框.进度条等功能的实现,本节主要针对自定义按钮进行讲解,这节过后,也希望大家对自定义有更深入的了解,在以后的功能开发 ...

  2. HDU 4023 (博弈 贪心 模拟) Game

    如果硬要说这算是博弈题目的话,那这个博弈是不公平博弈(partizan games),因为双方面对同一个局面做出来的决策是不一样的. 我们平时做的博弈都是公平博弈(impartial games),所 ...

  3. highCharts图表应用-实现多种图表的显示

    在数据统计和分析业务中,有时需要在一个图表中将柱状图.饼状图.曲线图的都体现出来,即可以从柱状图中看出具体数据.又能从曲线图中看出变化趋势,还能从饼状图中看出各部分数据比重.highCharts可以轻 ...

  4. BZOJ 1589 采集糖果

    23333怎么调了一晚上.... #include<iostream> #include<cstdio> #include<cstring> #include< ...

  5. 用canvas实现图片滤镜效果详解之视频效果

    这是一个很有意思的特效,模拟摄像机拍摄电视屏幕画面时出现点状颗粒的效果.颗粒的大小通过变换矩阵实现,可以任意调节,有兴趣研究的朋友可以尝试更多的效果,代码没有经过优化,只是一个粗糙的Demo,大家可以 ...

  6. 用canvas实现图片滤镜效果详解之灰度效果

    前面展示了一些canvas实现图片滤镜效果的展示,并且给出了相应的算法,下面来介绍一下具体的实现方法. 前面介绍的特效中灰度效果最简单,就从这里开始介绍吧. 1.获取图像数据 img.src = ’h ...

  7. python编码问题(1)

    一.字符编码基础 字符编码是计算机对字符的格式化,从而能够在计算机系统中存储与传输. 1.ASCII码 在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两种状态 ...

  8. 虚拟机下Linux系统安装vmtool工具

    1.启动此虚拟机2.用超级用户root登录3.登录成功后,Ctrl+Alt ,取出鼠标,点选菜单栏,虚拟机 →安装VMware工具 → Install4.待虚拟系统挂载了光盘后,弹出cdrom文件夹或 ...

  9. Android fragment源码全解析

    Fragment 相信基本上每个android developer都用过,但是知晓其原理 用的好的还是不多,今天就从源码的角度上来带着大家分析一下Fragment的源码,对fragment有了更深层次 ...

  10. redmine 2.5.2 安装后邮件无法发送

    找到redmine安装目录-apps->redmine->htdocs->conflg->configuration.yml email_delivery:    delive ...