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 – 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

Recommend

liuyiding

说白了就是个01背包,但是我场上竟然没推出来,大受打击,又把01背包整理了一遍,幸好队友给力。

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%I64d\n", n)
#define MAXN 600000

ll d[MAXN];
ll sum;
int s[45];
int n;
double p;
double mm[45];
void get_m()
{
    mm[0] = 1.0;
    repu(i, 1, 45) mm[i] = 2.0 * mm[i - 1];
    return ;
}

void dp()
{
    memset(d, 0, sizeof(d));
    d[0] = 1;
    for(int i = 1; i <= n; i++)
        for(int j = sum; j >= s[i]; j--)
               d[j] = d[j]+d[j-s[i]];
    return ;
}

int main()
{
    int T;
    sfi(T);
    get_m();
    while(T--)
    {
       sfi(n);
       scanf("%lf", &p);
       sum = 0;
       repu(i, 1, n + 1) { sfi(s[i]); sum += s[i];}
       dp();

       double num = 0.0;
       double monkey = (p * mm[n]);
       for(ll i = 0; i <= sum; i++)
       {
           num += d[i];
           if(num >= monkey)
           {
               printf("%I64d\n", i);
               break;
           }
       }
    }
    return 0;
}

时间: 2025-01-18 00:43:51

HDU4815的相关文章

HDU4815/计数DP

题目链接[http://acm.hdu.edu.cn/showproblem.php?pid=4815] 简单说一下题意: 有n道题,每到题答对得分为a[ i ],假如A不输给B的最小概率是P,那么A最少要得到多少分. 解题过程: 假设有n道题,每个题有两个状态,胜或者败,假设达到某个分数m有k(计数DP)种方式,那么最后是这个分数的概率是k/pow(2,n).那么A不输给B的概率就是小于等于m的分数的概率和. #include<bits/stdc++.h> const int maxn =

hdu4815 概率问题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 好久没写dp了..最开始题意都理解错了, 哎!!我现在很饿也很困!! AC代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; double dp[45][40005];

hdu4815 (概率DP)

由于没有专门练过概率DP , 场上硬推的,由于一点小失误WA了两发 . 我们很容易求出来d[i][j],表示前i道题,得分为j的概率 . 这样,最终打完所有题目之后猴子得任意分数的概率我们就知道了,老虎要想赢就要至少得和他一样的分数,那么就很好办了,从0~max分,不断相加概率,当概率大于P时的分数就是答案 . 细节见代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 5

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