搜索 。。。
平局和胜负局的数目可以求出。
然后按照 1-2,1-3,1-4 … ,1-n 的方式进行搜索。
可以得到 96 pts 。
如果我们当前局面之前搜索过的话,可以哈希后用 map 存下来。
实际上我们不用把当前是哪两个球队比赛记录下来,而是在一支球队搜索完过后判断剩下的球队的分数是不是之前搜索过,如果是就直接返回。
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int N=15;
const int P=13331;
//搜索 ...
//平局和胜负局的数目可以求出
//暴搜 + 剪枝
int n,a[N],tot1,tot2,sum;
map<ull,int> mp;
int dfs(int x,int y) {
if(y == n + 1) {
if(a[x] > 0) return 0;
x ++;
if(x == n) return 1;
ull tmp=0;
for(int i=x;i<=n;i++) tmp=tmp*P+a[i];
//记忆化
if(mp.find(tmp) != mp.end()) return mp[tmp];
return mp[tmp] = dfs(x, x + 1);
}
int res=0;
if(a[x]>=3&&tot1>0) {
a[x]-=3,tot1--,res+=dfs(x,y+1),a[x]+=3,tot1++;
}
if(a[y]>=3&&tot1>0) {
a[y]-=3,tot1--,res+=dfs(x,y+1),a[y]+=3,tot1++;
}
if(a[x]>=1&&a[y]>=1&&tot2>0) {
a[x]--,a[y]--,tot2--,res+=dfs(x,y+1),a[x]++,a[y]++,tot2++;
}
return res;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
for(int i=0;i<=n*(n-1)/2;i++) {
if(3*i+((n*(n-1)/2-i))*2==sum) tot1=i,tot2=n*(n-1)/2-i;
}
printf("%d",dfs(1,2));
}