HDU 4815 Little Tiger vs. deep Monkey (01 backpack)

Source: Internet
Author: User

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.

Surprised by the STS (speech to Speech) technology of Microsoft, and the cat Face recognition project of Google and academia? Is your curious about what technology was 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 (depth learning/deep neural network)", says the director. "However, they is only ' a piece of cake '. I won ' t tell you a top secret, our lab have invented a deep Monkey (Dark Monkey) with much advanced technology. And that guy is as smart as human! "

"Nani?!" Little Tiger doubts about that as he's the smartest kid in his kindergarten; Even so, he's not as smart as human, "How can a monkey be smarter than me?" I'll challenge him. "

To verify their-achievement, the researchers of the deep Lab is going to host a intelligence test for Little Ti Ger and Deep Monkey.

The test is composed of N binary choice questions. and different questions may has 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 would choose the answer randomly as he doesn ' t believe the Monkey is smart. Now, Little Tiger was wondering "What score should I get at least so that I'll not lose in the contest with probability O f at least P? ”. As Little Tiger is a really smart guy, he can evaluate the answer quickly.

You, the deep Monkey, can do 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 lines. The first line has both 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 are in the range of [0, 1]. The second line have N numbers separated by blanks, which is the scores of each question. The score of each questions is a integer and in the range of [1, 1000]?/div>

Output

For each test case, the output is only a single line with the answer.

Sample Input

3 0.51 2 3

Sample Output

3 topic: N-Question. Each problem has a certain score (if you answer a question, you will get the corresponding points, answer the question is not divided), two people to answer a random answer, ask B at least how many points to ensure that there is a probability of P will not lose (that is, the probability of 1-p will win) 01 knapsack problem, Dp[i][j] said I question the probability of a total of J points, Then answer the i+1 answer there are two cases, it is possible to answer the right or wrong, each accounted for 0.51. I+1 answer correctly, then the probability of the score is dp[i+1][j+a[i]; (A[i] Indicates the score of the i+1 question, since I is starting from 0) 2. I+1 answer wrong, The probability of scoring is dp[i+1][j], the sum of the probabilities of the various scores of the N-Questions is x, and then the score can be output when x satisfies the condition x>1-p;
#include <stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespacestd;Const intN = -;Const intM =40010;intA[n];DoubleDp[n][m];intMain () {intT, N; Doublep; scanf ("%d", &t);  while(t--) {scanf ("%D%LF", &n, &p);  for(inti =0; I < n; i++) scanf ("%d", &A[i]); Memset (DP,0,sizeof(DP)); dp[0][0] =1;//the probability of writing 0 questions to 0 points is 1.         for(inti =0; I < n; i++)        {             for(intj =0; J < n * +; J + +) {Dp[i+1][J] + = dp[i][j] *0.5;//The first i+1 question did not write right, did not get the points of the problemDp[i +1][j + a[i]] + = dp[i][j] *0.5;//Section I+1 wrote the right, got the points of the problem            }        }        Doublex =0; intm =0;  for(intj = n * +; J >=0; j--) {x+ = Dp[n][j];//write the probability of each score of n-Question and            if(X >1-p) {m=J;  Break; }} printf ("%d\n", M); }    return 0;}

HDU 4815 Little Tiger vs. deep Monkey (01 backpack)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.