HDU 4815 little tiger vs. Deep monkey backpack Problems

Source: Internet
Author: User

Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4815

Question: a question that is very "connotation". The question is to give n questions and a probability P, then give the corresponding score AA [I] for each question (each question has only two options, one correct and one wrong ). When two people answer questions, one person selects the answer at random and asks another person at least how many points should be answered to ensure that the probability of P will not fail.

Idea: It was a DP question. I first tried to forcibly enumerate all the cases and find the scores I needed. Then I found that the 40 questions forcibly enumerating 2 ^ 40 would inevitably time out, and the idea was interrupted. Then I thought of DP, at the beginning, the possible score of DP was very unreliable. It was found that it was a 01 backpack problem. You can choose to put each question into a backpack or not into a backpack, the number of types corresponding to each score record. Then the search can meet the conditions from small to large, that is, the sum of the conditions corresponds to a probability greater than the score of P.

Code:

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include<cstdlib>#include<queue>#include<stack>#include<vector>#include<ctype.h>#include<algorithm>#include<string>#define PI acos(-1.0)#define maxn 10005#define INF 0x7ffffffftypedef long long ll;using namespace std;long long vis[40005];long long dd[45];int init(){    dd[1]=2;    for(int i=2; i<=40; i++)        dd[i]=dd[i-1]*2;}int main(){    int tot;    int T;    scanf("%d",&T);    init();    while(T--)    {        scanf("%d",&tot);        double pos;        memset(vis,0,sizeof(vis));        vis[0]=1;        scanf("%lf",&pos);        int aa[45];        int bb=0;        for(int i=0; i<tot; i++)        {            scanf("%d",&aa[i]);            bb+=aa[i];        }        sort(aa,aa+tot);        for(int i=0; i<tot; i++)        {            for(int j=bb; j>=aa[i]; j--)            {                vis[j]+=vis[j-aa[i]];            }        }        long long cc=0;        for(int k=0; k<=bb; k++)        {            cc+=vis[k];            double ee=cc;            double ff=dd[tot];            double rec=ee/ff;            if(rec>=pos)            {                printf("%d\n",k);                break;            }        }    }    return 0;}


HDU 4815 little tiger vs. Deep monkey backpack Problems

Related Article

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.