看起来很神,看到数据范围就呵呵了。
program p1800; var x:array[1..4] of longint; d:array[1..20,1..20] of int64; i,j,n,tot:longint; procedure dfs(k1,k2:longint); var i,j:longint; begin if k2>4 then begin if (d[x[1],x[2]]=d[x[3],x[4]]) and (d[x[2],x[3]]=d[x[4],x[1]]) then inc(tot); exit; end; for i:=k1 to n do begin x[k2]:=i; dfs(i+1,k2+1); end; end; begin readln(n); for i:=1 to n do read(d[i,i mod n+1]); for i:=1 to n do begin j:=(i+1) mod n+1; while j<>i do begin d[i,j]:=d[i,(j-2+n) mod n+1]+d[(j-2+n) mod n+1,j]; j:=j mod n+1; end; end; tot:=0; dfs(1,1); writeln(tot); end.