大数什么的果断python 无压力.....
Code:
dp=[]
def check(a,cur):
for i in xrange(0,3) :
if i!=cur:
if a[i]!=0:
return 0
return 1
def dfs(a,cur):
if dp[cur][a[0]][a[1]][a[2]]!=-1:
return dp[cur][a[0]][a[1]][a[2]]
if check(a,cur):
if a[cur]==1 and cur!=0:
dp[cur][a[0]][a[1]][a[2]] = 1
else :
dp[cur][a[0]][a[1]][a[2]] = 0
return dp[cur][a[0]][a[1]][a[2]]
dp[cur][a[0]][a[1]][a[2]] = 0
for i in xrange(0,3):
if i!=cur and a[i]:
b=[]
for j in xrange(0,3):
b.append(a[j])
b[cur]-=1;
dp[cur][a[0]][a[1]][a[2]] += dfs(b,i)*b[i]
return dp[cur][a[0]][a[1]][a[2]]
n = int(raw_input())
for i in xrange(0,3):
a=[]
for j in xrange(0,1+n):
c=[]
for k in xrange(0,n+1):
d=[]
for z in xrange(0,n+1):
d.append(-1)
c.append(d)
a.append(c)
dp.append(a)
a=[]
for i in xrange(0,3):
a.append(n)
ans = dfs(a,0)/2;
print ans