BNU29370:Enthusiast

Ryan is an enthusiast of music. For almost all the time, there is a headphone on his ear. In his music player, there are N different songs, and he always plays those songs in random mode, never know what’s going next.

But this morning he finds an incredible fact, the player play one song for three times continuously! He wonders how small the probability this similar things can happen. Given all the song names in the player, and the sequence indicating the song names play successively, calculate the probability it happens.

Input

The first line contains a single integer T, indicating the number of test cases.
Then two integers N and M (1<=N, M<=16) follow, N indicates the number of songs, and M indicated the length of the sequence.
Then N strings follow, indicating the names of the different N songs, and then another M strings, indicating the song names in the sequence Ryan hears. The length of all the string is less than 16, including blanks maybe. You may assume the M names are all from the player list.

Output

For each test case, output the case number first, then the probability rounded to six fractional digits.

Sample Input

2
1 1
Opera
Opera
3 3
The Rainy Day
Hey Jude
Opera
Opera
Opera
Opera

Sample Output

Case 1: 1.000000
Case 2: 0.037037
题意:给出每首歌的歌名还有唱歌的顺序,求出按给出顺序唱歌的概率
思路:其实很简单,因为每首歌都是独一无二的,所以按照顺序唱,每次唱的那首歌的概率都是一定的
 
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

char song[100];

int main()
{
    int t,cas = 1,i,n,m;
    double ans;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(i = 0; i<=n+m; i++)
            gets(song);
        ans = 1.0/n;
        ans = pow(ans,m);
        printf("Case %d: %.6f\n",cas++,ans);
    }

    return 0;
}

你可能感兴趣的:(水,BNU)