hdu 4815 Little Tiger vs. Deep Monkey DP(概率类 较简单)


题意:n个题目,每个题目有一定的分值,猴子答对打错的概率相同。

给出一个概率p,试问你至少要有多少分才会有  P{你的分>=猴子分}=p


Little Tiger vs. Deep Monkey

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 2057    Accepted Submission(s): 722


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
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   5717  5716  5715  5714  5713 
 

Statistic |  Submit |  Discuss |  Note

很简单,求出猴子分数为x时的概率dp[x],

然后求最小的正整数k使得  dp[0]+...+dp[k]>=p即可。


其中概率dp[x]就是用分值x的种数除以全排列A[n]即可。

具体的实现方式应该有母函数和dp(计数dp,背包)。


#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)
#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)
typedef long long ll;
typedef pair<int, int> pii;
const int INF =0x3f3f3f3f;
const int maxn= 40    ;
const int maxV=40*1000;
int n,V;
double p;
double dp[maxV+10];//dp[x]表示分数为x的概率
int a[maxn+4];//每道题的得分
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%d%lf",&n,&p);
        V=0;
        for1(i,n)
        {
            scanf("%d",&a[i]);
            V+=a[i];
        }
       memset(dp,0,(V+1)*sizeof dp[0]);
       dp[0]=1;
       for1(i,n)
       {
           for(int v=V;v>=a[i];v--)
           {
               dp[v]+=dp[v-a[i]];
           }
       }
       double ret=pow(2,n);
       for0(v,V+1) dp[v]/=ret;

       double win=0;
       for0(i,V+1)
       {
           win+=dp[i];
           if(win>=p)
           {
               printf("%d\n",i);
               break;
           }
       }


    }

   return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值