Problem:


整数の和

0 から 9 の数字から異なる n 個の数を取り出して合計が s となる組み合わせの数を出力するプログラムを作成してください。n 個の数はおのおの 0 から 9 までとし、１つの組み合わせに同じ数字は使えません。たとえば、n が 3 で s が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、

1 + 2 + 3 = 6

0 + 1 + 5 = 6

0 + 2 + 4 = 6

の 3 通りとなります。

Input

複数のデータセットが与えられます。各データセットに n (1 ≤ n ≤ 9) と s (0 ≤ s ≤ 100) が１つのスペースで区切られて１行に与えられます。n と s が共に 0 のとき入力の最後とします（この場合は処理せずにプログラムを終了する）。

データセットの数は 50 を超えません。

Output

各データセットに対して、n 個の整数の和が s になる組み合わせの数を１行に出力して下さい。

Sample Input

3 6
3 1
0 0

Output for the Sample Input

3
0



Sample input:
3 6
3 1
0 0


Sample output:
3
0

Submission status: Runtime Error

Solution code:
from collections import deque


class Bt(object):
    def __init__(self):
        self.used = [False] * 10  # 0-9????????°???????????¨?????????????????????????????°
        self.answers = []  # ?????¶???????????????????????????
        self.Q = deque()  # ????????§???????????¢??????????????°???????¨???¶??¨

    def solve(self, num, remain):
        # ????´¢??????????°??????§?????????????????????????????§????????????????????§????????°??????????????????????????????
        try:
            min_choice = max(self.Q) + 1
        except ValueError:
            min_choice = 0

        if min_choice <= remain < 10 and self.used[remain] == False and num == 1:
            self.Q.append(remain)
            # print('{0}'.format(self.Q))
            ans = [*self.Q]
            ans.sort()
            if not ans in self.answers:
                self.answers.append(ans)
            self.Q.pop()
            # self.answers.append(1)
            return
        elif num < 0:
            return

        for i in range(min_choice, 10):
            if self.used[i] == False and (remain - i) >= 0:
                self.used[i] = True
                self.Q.append(i)
                self.solve(num - 1, remain - i)
                self.used[i] = False
                self.Q.pop()


if __name__ == '__main__':
    while True:
        # ??????????????\???
        n, s = [int(x) for x in input().split(' ')]
        if n == 0 and s == 0:
            break

        if 0 <= s <= 45:
            # ????????????
            a = Bt()
            a.solve(n, s)

            # ???????????¨???
            print(len(a.answers))
        else:
            print(0)

Submission status: Runtime Error

Solution code:
class Depth_First_Search_stack:
    def __init__(self, n, s):
        self.n = n
        self.s = s
        self.stack=[[i] for i in range(self.s)]
        self.ans = 0

    def search(self):
        while self.stack:
            c = self.stack.pop()
            if sum(c) == self.s and len(c) == self.n:
                self.ans += 1
            for i in range(max(c)+1, self.s-max(c) + 1):
                if sum(c+[i]) <= self.s and len(c+[i]) <= self.n:
                    self.stack.append(c+[i])

if __name__ == '__main__':
    while 1:
        n, s = list(map(int, input().split(' ')))
        if n==0 and s==0:
            break
        DFS = Depth_First_Search_stack(n, s)
        DFS.search()
        print(DFS.ans)
~

Submission status: Runtime Error

Solution code:
def solve(n,s,lst):
    if n == 0 and s == 0:
        return(1)
    elif s < lst[0] or len(lst)==0:
        return(0)
    else:
        return(solve(n-1,s-lst[0],lst[1:]) + solve(n,s,lst[1:]))

if __name__ == "__main__":
    while True:
        n, s = map(int, input().split())
        if n==0 and s==0:
            break
        print(solve(n,s,list(range(9))))

Submission status: Runtime Error

Solution code:
while 1:
 n,s=map(int,input().split())
 if n:print(len([1 for i in range(0,8)for j in range(i+1,9)if j<s-i-j<=9]))

Submission status: Runtime Error

Solution code:
from itertools import combinations
while 1:
 n,s=map(int,input().split())
 if n:print(sum(1 for p in combinations(range(10),n)if sum(p)==s))

Submission status: Runtime Error

Solution code:
from itertools import combinations
while 1:
 n,s=map(int,input().split())
 if n+x==0:break
 print(sum(1 for p in combinations(range(10),n)if sum(p)==s))

Submission status: Runtime Error

Solution code:
from itertools import combinations
while 1:
 n,s=map(int,input().split())
 if n:print(sum([1 for p in combinations(range(10),n)if sum(p)==s]))

Submission status: Runtime Error

Solution code:

import itertools

while True:
    a,b = map(int, raw_input().split(' '))
    count = 0
    
    if a == 0 and b == 0:
        break
    else:
        for com in itertools.combinations([0,1,2,3,4,5,6,7,8,9],a):
            if sum(com) == b:
                count += 1
        
        print count

Submission status: Runtime Error

Solution code:
import itertools
 
while True:
    a,b = map(str, raw_input().split(' '))
    a = int(a)
    b = int(b)
    count = 0
     
    if a == 0 and b == 0:
        break
    else:
        for com in itertools.combinations([0,1,2,3,4,5,6,7,8,9],a):
            if sum(com) == b:
                count += 1
         
        print count

Submission status: Runtime Error

Solution code:
while True:
    (n, s) = [int(i) for i in raw_input().split()]
    if((0,0) == (n,s)):
        break
    r = xrange(10**(n-1),10**n)
    r = map(str,r)
    r = filter(lambda x:len(set(x)) == len(x),r)
    r = map(lambda x:map(int,x),r)
    r = filter(lambda x:reduce(lambda x,y:x+y,x) == s, r)
    print len(r)

Submission status: Runtime Error

Solution code:

import sys


def subset(a):
    for n in range(2**len(a)):
        yield [a[i] for i in xrange(len(a)) if (n >> i) & 1 == 1]



for line in sys.stdin:
    (n, s) = tuple(map(int, line.rstrip('\r\n').split(' ')))
    if n == 0 and s == 0:
        exit()
    x = 0
    for b in subset(range(10)):
        if len(b) == n and sum(b) == s:
            x += 1
    print x

Submission status: Runtime Error

Solution code:
def dec2bin(n, base=10):
    s=""
    x=["0","1"]
    while n>0:
        s+=x[n%2]
        n/=2
    return (s+"0"*base)[:base]

x=[[0 for i in range(50)] for i in range(11)]
for i in range(0, 2**10):
    tmp = dec2bin(i)
    s=0
    c=0
    for j in range(10):
        if tmp[j]=="1":
            s+=j
            c+=1
    x[c][s]+=1

while True:
    n,s=map(int, raw_input().split())
    if n==0 and s==0: break
    print x[n][s]

Submission status: Runtime Error

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j += 1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print [x[n][s],0][s>=50]

Submission status: Runtime Error

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s+=j; c+=1
        j　+=　1
    x[c][s]　+=　1

while 1:
    n,s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]