SRM 453 div1 easy
勝敗を全列挙する
#coding: utf-8 def solve(i,j,s,P,N,M): ret = 0 if i == j: if i == N-1: k = sorted(s) k.reverse() ss = tuple(k) if ss[0] == M: if ss not in P: P.add(ss) ret = 1 else: ret = solve(0,j+1,s,P,N,M) else: # i vs j s[j] += 2 ret += solve(i+1,j,s,P,N,M) s[j] -= 2 s[i] += 1 s[j] += 1 ret += solve(i+1,j,s,P,N,M) s[i] -= 1 s[j] -= 1 s[i] += 2 ret += solve(i+1,j,s,P,N,M) s[i] -= 2 return ret class TheBasketballDivOne: def find(self, n, m): P = set([]) if m > 2*n: return 0 scores = [0 for i in range(n)] return solve(0,0,scores,P,n,m)