这题嘛,我们可以首先考虑枚举一共n*(n-1)/2次比赛的结果,然后判断一下就好了
其实有一点是显然的,分数序列的顺序不影响答案
所以我们用最小表示法来表示分数序列,然后记忆化搜索一下就好了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int p=(1e9)+7;
map<ll,ll>mp;
int n;
struct state{
int a[11];
ll hash(){
ll ans=0;
for(int i=0;i<=n;i++)ans=ans*28+a[i];
return ans;
}
void minexp(){
sort(a+a[0],a+n+1);
}
}st,ed;
ll dfs(int i,state now){
if(now.a[0]==n)return mp[now.hash()]=-1;
if(now.a[now.a[0]]>3*(n-i+1))return -1;
if(i>n){
now.a[0]++;
now.minexp();
if(mp[now.hash()])return mp[now.hash()];
return dfs(now.a[0]+1,now);
}
ll ans=0,tmp;
int idx=now.a[0];
if(now.a[idx]>=3){
now.a[idx]-=3;
tmp=dfs(i+1,now);
if(tmp!=-1)(ans+=tmp)%=p;
now.a[idx]+=3;
}
if(now.a[idx]&&now.a[i]){
now.a[idx]--;now.a[i]--;
tmp=dfs(i+1,now);
if(tmp!=-1)(ans+=tmp)%=p;
now.a[idx]++;now.a[i]++;
}
if(now.a[i]>=3){
now.a[i]-=3;
tmp=dfs(i+1,now);
if(tmp!=-1)(ans+=tmp)%=p;
now.a[i]+=3;
}
ans=ans?ans:-1;
if(i==idx+1)mp[now.hash()]=ans;
return ans;
}
int main(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",st.a+i);
st.a[0]=1;
st.minexp();
ed.a[0]=n;mp[ed.hash()]=1;
printf("%lld\n",dfs(2,st));
return 0;
}