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.
#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; }