HDU 4815 2013 event C in Changchun

Source: Internet
Author: User

C-Little Tiger vs. Deep monkey Time limit:1000 ms Memory limit:65535kb 64bit Io format:% I64d & % i64usubmit status practice HDU 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 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 (deep learning/deep Neural Network)", says the director. "However, they are only 'a piece of cake '. I won't tell you a top secret that our lab has too Ted a deep monkey (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 shocould 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

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, 10 00]? /Div>

Output

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

Sample Input

 13 0.51 2 3 
 

Sample output

 3 

This question is so funny. At first, the Emperor told me that I may have understood the question wrong. Then I used binary enumeration! Then ...... Then we spent more than an hour in WA. After the Emperor realized that I had understood it wrong, he knocked on his backpack again ...... Alas ...... I found the question a little hard to understand. By now, both the question and solution are well-understood.

The correct solution is: the total situation is: 1 <n, then the number of times that can be combined divided by the total situation> = the minimum score of P is the correct answer.

#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;long long dp[40005];int main(){    int t;    cin>>t;    while(t--)    {        int n,i,j,sum=0,a[45];        double p;        memset(dp,0,sizeof(dp));        dp[0]=1;        cin>>n>>p;        for(i=0;i<n;i++)            scanf("%d",a+i),sum+=a[i];        sort(a,a+n);        for(i=0;i<n;i++)            for(j=sum;j>=a[i];j--)                dp[j]+=dp[j-a[i]];        long long sum1=1LL<<n,sum2=0;        for(i=0;i<=sum;i++)        {            sum2+=dp[i];            if((double)sum2/(double)sum1>=p)            {                printf("%d\n",i);                break;            }        }    }    return 0;}


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.