P2111 examination adventure

Topic background

A city of God school in a school bully, his name is called the Little Ming (in order to protect the privacy of the hero, his name as "Bob" instead). In the midterm exam, Xiao Ming students go peach blossom, met a girl in the examination room, her name is red (the same is to protect privacy).

Title Description

English exams are over, so after the bell, she would take the initiative to come to Xiao Ming to speak, the one we should take the English examination paper to answer. Xiao Ming is recognized as the god of English, apart from anything else put the papers lent her. Red to again answer, simply are vastly different, she can not help emitting a cold sweat. At this time, Xiao Ming came over to comfort her:. "Nothing, I'm not the standard answer, not necessarily all of the"

Accuracy is known to Bob answers A%, a total of N questions, answers given result S of the red (a string of length N 01, where 1 denotes the same two answers, 0 indicates not the same). To simplify matters, all the questions are True or False.

You help the little red write a program that calculates the probability of her title Q and above.

(PS Xiao Ming later gave the examination paper goes red, do not think more, not a token of love)

Input Format

Line 1, three positive integers N, A, Q.

Line 2, 01 a string S.

Output Format

Line, a real number, said she probability Q questions and more. (Three decimal places)

Sample input and output

Input # 1
3 90 2
100
Output # 1
0.172

Description / Tips

Data for 90%, N <= 50, N-5 <= Q <= N.

For the remaining 10% of the data, N <= 10000, Q = 0.

 

 

From the beginning of the enumeration p, that is, just do the right p from the title, to do the enumeration of all the problems.

Do the right questions of the right title = + two identical two different red and do the right questions.

As for the formula is purely a binomial distribution formula.

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n,a,q,com,unc;

double rt,p;

char s[6666];

long long c[222][333];

int main(){
    scanf("%d%d%d",&n,&a,&q);
    scanf("%s",s+1);
    if(n>50){
        printf("1.000");
        return 0;
    }
    rt=(double)a/(double)100;
    c[0][0]=c[1][1]=c[1][0]=1;
    for(int i=1; i<=50; i++){
        c[i][0]=c[i][i]=1;
        for(int j=1; j<i; j++){
            c[i][j]=c[i-1][j]+c[i-1][j-1];
        }
    }
    for(int i=1; i<=strlen(s+1); i++){
        if(s[i]=='1'){
            com++;
        }
        else if(s[i]=='0'){
            unc++;
        }
    }
    for(int i=q; i<=strlen(s+1); i++){
        for(int j=0; j<=i; j++){
            int ncom=j,nunc=i-j;
            if(ncom>com||nunc>unc){
                continue;
            }
            double p1=c[com][ncom]*pow(rt,ncom)*pow(1-rt,com-ncom);
            double p2=c[unc][nunc]*pow(1-rt,nunc)*pow(rt,unc-nunc);
            p=p+p1*p2;
        }
    }
    printf("%.3lf",p);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hrj1/p/11521673.html