hdu 4815 Little Tiger vs. Deep Monkey(01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=4815
Description
“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
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
Sample Input
Sample Output
#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背包)的更多相关文章
- HDU4815 Little Tiger vs. Deep Monkey——0-1背包
题目描述 对于n道题目,每道题目有一个分值,答对加分,答错不得分,你要和一个叫深猴的比赛,题目你可以假设成判断题(不是对就是错),深猴对于所有的题目都是随机选择一个答案,而你是有脑子的,求为了不输掉比 ...
- HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 简单的DP题. #include <stdio.h> #include <st ...
- HDU 4815 Little Tiger vs. Deep Monkey 2013 长春现场赛C题
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 [题意] n个题目,每题有各自的分数,A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率 ...
- hdu 4815 Little Tiger vs. Deep Monkey
概率dp,有点像背包的做法: dp[i][j]代表前i个数组成的j数的概率为多少 #include<cstdio> #include<cstring> #define maxn ...
- 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的概率 ...
- hdu 2126 Buy the souvenirs 二维01背包方案总数
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 1203 I NEED A OFFER!(01 背包DP)
点我看题目 题意 : 中文题不详述. 思路 :类似于01背包的DP,就是放与不放的问题,不过这个要求概率,至少得到一份offer的反面就是一份也得不到,所以先求一份也得不到的概率,用1减掉就可以得到所 ...
- HDU 5887 Herbs Gathering(搜索求01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=5887 题意: 容量很大的01背包. 思路: 因为这道题目背包容量比较大,所以用dp是行不通的.所以得用搜索来做, ...
- HDU 3339 In Action【最短路+01背包】
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Other ...
随机推荐
- .net4.0下 解决asp.net中“从客户端中检测到有潜在危险的Request.Form值”的错误
asp.net 2.0 通常解决办法 方案一: 将.aspx文件中的page项添加ValidateRequest="false" ,如下: <%@ Page Validate ...
- I.MX6 AT24Cxx eeprom Linux i2c-gpio
/************************************************************************** * I.MX6 AT24Cxx eeprom L ...
- 20160206.CCPP体系详解(0016天)
代码片段(01):.指针.c+02.间接赋值.c 内容概要:内存 ///01.指针 #include <stdio.h> #include <stdlib.h> //01.取地 ...
- mysql mac启动
设置别名 alias mysql=/usr/local/mysql/bin/mysql alias mysqladmin=/usr/local/mysql/bin/mysqladmin 修改密码 su ...
- 项目中使用的ajax异步读取数据结构设计
设计稍微复杂了一点,完成ajax读取功能涉及到了很多页面.虽然如此,但感觉比较灵活. 和传统方法唯一的区别在于多了一层数据容器控件,里面提供了显示数据的HTML元素及相应的JS方法. 这样数据控件指生 ...
- 重拾Excel之为什么
现在如今想想自己,已经有许久许久没有充过电了.现在想好好地充电. 机遇总是垂青于有准备的人!
- 用vs2012的命令利用xsd文件生成对应的C#类,把xml的string类型映射到生成的类
输入命令: xsd d:\TDDOWNLOAD\atom-author-link.xsd /c /language:C# /outputdir:d:\ 含义: 将d:\TDDOWNLOAD\atom- ...
- 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
Dixon 原文 用ArcGIS Engine.VS .NET和Windows控件开发GIS应用 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...
- Linux中用stat命令查看文件时3个时间点解析
有些时候,我们需要在Linux中使用stat命令来查看文件的详细信息.另外联想下,ls -l命令显示的是什么时间,touch命令修改文件的时间戳,修改的又是什么时间?在这里我们一起来试验下. 首先,我 ...
- 搭建XMPP协议,实现自主推送消息到手机
关于服务器端向Android客户端的推送,主要有三种方式: 1.客户端定时去服务端取或者保持一个长Socket,从本质讲这个不叫推送,这是去服务端拽数据.但是实现简单,主要缺点:耗电等 2.Googl ...