HDOJ 4815 Little Tiger vs. Deep Monkey

递推...

Little Tiger vs. Deep Monkey

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

Total Submission(s): 661    Accepted Submission(s): 244

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

2013 Asia Regional Changchun

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const double eps=1e-10;

double dp[44000],tp[44000],p;
int n,fen[50];

int main()
{
    int T_T;
    scanf("%d",&T_T);
    while(T_T--)
    {
        scanf("%d%lf",&n,&p);
        memset(dp,0,sizeof(dp));
        dp[0]=1.;
        for(int i=0;i<n;i++)
        {
            scanf("%d",fen+i);
            memset(tp,0,sizeof(tp));
            for(int j=0;j<40010;j++)
            {
               if(dp[j]>eps)
               {
                    tp[fen[i]+j]+=dp[j]*0.5;
                    tp[j]+=dp[j]*0.5;
               }
            }
            memcpy(dp,tp,sizeof(tp));
        }
        double sum=0;
        int ans=-1;
        for(int i=0;i<40010;i++)
        {
            if(dp[i]>eps)
            {
                sum+=dp[i];
                if(sum+eps>=p)
                {
                    ans=i;
                    break;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
时间: 2025-01-07 13:47:09

HDOJ 4815 Little Tiger vs. Deep Monkey的相关文章

hdu 4815 Little Tiger vs. Deep Monkey(01背包)

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 recogn

HDU 4815 Little Tiger vs. Deep Monkey

http://acm.hdu.edu.cn/showproblem.php?pid=4815 题意: 给定N个题目各自的分数a[i] A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率上总分不低于A 问B至少要得到多少分 解法: 概率DP dp[i][j]表示前i题得到j分的概率 递推式: dp[i][j] = dp[i-1][j] * 0.5 (a[i]>j) dp[i][j] = (dp[i-1][j] + dp[i-1][j - a[i]]) * 0.5 (a[i]<=j)

HDU 4815 Little Tiger vs. Deep Monkey 背包问题

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 题意:很"内涵"的一个题面,题意是给出N道题,和一个概率P,然后给出每道题对应的得分aa[i](每道题只有两个选项,一个正确一个错误).两个人来答题,一个人是随机选择答案,问另一个人至少要答多少分才能保证有P的概率不会失败. 思路:是一道DP题,最开始想强行枚举所有情况,找到需要分数,后来发现40道题强行枚举2^40必然超时,思路就中断了,后来想到DP,刚开始DP的可能得到的分数,但是很

Little Tiger vs. Deep Monkey(01背包)

Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 3715    Accepted Submission(s): 1276 Problem Description A crowd of little animals is visiting a mysterious laborator

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

题目描述 对于n道题目,每道题目有一个分值,答对加分,答错不得分,你要和一个叫深猴的比赛,题目你可以假设成判断题(不是对就是错),深猴对于所有的题目都是随机选择一个答案,而你是有脑子的,求为了不输掉比赛(平局或你获胜)的可能性至少为p时你至少需要得到多少分,有t组数据,每次输入两行,第一行为n,p(有n道题目,n<=40, 不会输的可能性为p,0.0<=p<=1.0),第二行输入n个1~1000的整数,代表这n道题分别答对能获得的分数 样例输入 1 3 0.5 1 2 3 样例输出 3

HDU 4815 2013长春现场赛C题

C - Little Tiger vs. Deep Monkey Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4815 Description A crowd of little animals is visiting a mysterious laboratory ? The Deep Lab of SYSU. "Are y

2013 Asia Regional Changchun

Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 1 #include<cstdio> 2 char op[1024]; 3 int main(){ 4 int t,n,m; 5 while(~scanf("%d",&t)){ 6 while(t--){ 7 scanf("%d%d%s",&n,&m,op); 8 for(int i=0;i<n;i++){ 9

2013 Asia Regional Changchun C

Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 960    Accepted Submission(s): 344 Problem Description A crowd of little animals is visiting a mysterious laboratory

HDU4815

Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1587    Accepted Submission(s): 566 Problem Description A crowd of little animals is visiting a mysterious laboratory