zoukankan      html  css  js  c++  java
  • Little Tiger vs. Deep Monkey(01背包)

    Little Tiger vs. Deep Monkey

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


    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
     
    题目意思:  求解最小的得分以至少为p的不会输;
     
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    int t;
    int n;
    int arr[50];
    double dp[50][40010];     //几道题 几分的 概率
    double pp;
    
    int main(){
        cin>>t;
        while(t--){
            cin>>n>>pp;
            for(int i=0;i<n;i++){
                cin>>arr[i];
            }
            memset(dp,0,sizeof(dp));
            dp[0][0]=1.0;   //0道题0分的概率为1
            for(int i=0;i<n;i++){
                for(int j=0;j<n*1000;j++){
                    dp[i+1][j]+=dp[i][j]*0.5;   //得分为j的总数
                    dp[i+1][j+arr[i]]+=dp[i][j]*0.5;
                }
            }
            double res=0;
            int flag=0;
            for(int i=n*1000;i>=0;i--){   //注意0也是一种得分
                res+=dp[n][i];
                if(res>1-pp) {flag=i;break;}
            }
            cout << flag << endl;
        }
        return 0;
    }
    第一种
     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 int t;
     8 int n;
     9 int arr[50];
    10 int dp[40005];
    11 double pp;
    12 
    13 int main(){
    14     cin>>t;
    15     while(t--){
    16         memset(dp,0,sizeof(dp));
    17         int sum=0;
    18         dp[0]=1;   //0题的概率为1
    19         cin>>n>>pp;
    20         for(int i=1;i<=n;i++){
    21             cin>>arr[i];
    22             sum+=arr[i];
    23         }
    24         for(int i=1;i<=n;i++){
    25             for(int j=sum;j>=arr[i];j--){
    26                 dp[j]+=dp[j-arr[i]];   //得分为j的总数
    27             }
    28         }
    29         double tot=pow(2.0,n);
    30         double res=0;
    31         for(int i=0;i<=sum;i++){   //注意0也是一种得分
    32             res+=dp[i]/tot;
    33             if(res>=pp) {cout << i << endl;break;}
    34         }
    35     }
    36     return 0;
    37 }
    第二种
  • 相关阅读:
    【Educational Codeforces Round 36 C】 Permute Digits
    【Educational Codeforces Round 36 B】Browser
    【Educational Codeforces Round 36 A】 Garden
    【习题 8-14 UVA
    【习题 8-13 UVA
    【习题 8-12 UVA
    【习题 8-11 UVA
    【习题 8-10 UVA
    关于货仓选址问题的方法及证明(在数轴上找一点使得该点到所有其他点的距离之和最小)
    P2512 [HAOI2008]糖果传递
  • 原文地址:https://www.cnblogs.com/qq-1585047819/p/11687499.html
Copyright © 2011-2022 走看看