題意:
給出n個字符串,每次比賽任意選擇兩個,只能做兩種操作
1.選擇一個字符串消去後面一個字符。
2.如果兩個字符串相等,可以同時消去。
最後不能進行操作的一方輸。
問,後手失敗的概率,也即先手贏的概率。
分析:
剛開始審錯題了,還以爲所有的字符串都要用。。。這題有種博弈的感覺。
任選兩個串的話,那麼分母就是n*(n-1)/2中情況了。
然後分析何時先手贏。
1.對於a、b兩個串,如果|a|+|b|=奇數,那麼先手選擇較短的那個串,這樣就保證先手贏。
2.如果 |a|+|b|=偶數,那麼只有a==b的情況下先手贏,否則就是後手處於第一種情況了,那麼先手必輸。所以總共先手贏的情況就兩種,加起來就可以了。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define read freopen("q.in","r",stdin)
#define LL __int64
#define maxn 100005
using namespace std;
map<string,int> mp;
int gcd(int a, int b)
{
if(b==0)return a;
else return gcd(b,a%b);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
mp.clear();
int i,j,n;
string str;
cin>>n;
int odd=0,even=0;
int ans=0;
for(i=0;i<n;i++)
{
cin>>str;
if(str.length()&1)odd++;
else even++;
ans+=mp[str]++;
}
int res=n*(n-1)/2;
ans+=odd*even;
int g=gcd(ans,res);
cout<<ans/g<<"/"<<res/g<<endl;
}
}