Description
ZCC has got N strings. He is now playing a game with Miss G.. ZCC will pick up two strings among those N strings randomly(A string can't be chosen twice). Each string has the same probability to be chosen. Then ZCC and Miss G. play in turns. Miss G. always plays first. In each turn, the player can choose operation A or B.
Operation A: choose a non-empty string between two strings, and delete a single letter at the end of the string.
Operation B: When two strings are the same and not empty, empty both two strings.
The player who can't choose a valid operation loses the game.
ZCC wants to know what the probability of losing the game(i.e. Miss G. wins the game) is.
Operation A: choose a non-empty string between two strings, and delete a single letter at the end of the string.
Operation B: When two strings are the same and not empty, empty both two strings.
The player who can't choose a valid operation loses the game.
ZCC wants to know what the probability of losing the game(i.e. Miss G. wins the game) is.
Input
The first line contains an integer
which denotes the number of test cases.
For each test case, there is an integer in the first line. In the next N lines, there is a single string which only contains lowercase letters. It's guaranteed that the total length of strings will not exceed 200000.
For each test case, there is an integer in the first line. In the next N lines, there is a single string which only contains lowercase letters. It's guaranteed that the total length of strings will not exceed 200000.
Output
For each test case, output an irreducible fraction "p/q" which is the answer. If the answer equals to 1, output "1/1" while output "0/1" when the answer is 0.
Sample Input
1 3 xllendone xllendthree xllendfour
Sample Output
2/3
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
//如果两个字符串完全相同就MissG赢
//奇数的话 G赢 5 -1(G)-1-1(G)-1-1(G) 最后一步由G走
int m,n;
map<string,int> mm;
void gcd()
{
int m1=m,n1=n;
int a=1;
if(m>n) swap(m,n);//使m成为较小的一个数
while(m!=0)
{
a=n%m;
n=m;
m=a;
}
m=m1/n;
n=n1/n;
}
int main()
{
int T,N;
string s;
scanf("%d",&T);
while(T--)
{
m=0;
mm.clear();
int j=0,o=0;
scanf("%d",&N);
for(int i=0; i<N; i++)
{
cin>>s;
int len=s.size();
if(len%2!=0) j++;//奇
else o++;//偶
if(mm.count(s)==0) mm[s]=1;
else
{
m+=mm[s];
mm[s]++;
}
}
m+=o*j;//加上奇*偶
n=N*(N-1)/2;
gcd();
if(m==0) printf("0/1\n");
else printf("%d/%d\n",m,n);
}
return 0;
}