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: Accepted

Solution code:
import sys
import itertools

for line in sys.stdin:
    (n, s) = map(int, line.split(" "))
    if n == 0 and s == 0:
        break
    cnt = 0
    for v in itertools.combinations(range(10), n):
        cnt += sum(v) is s
    print(cnt)

Submission status: Accepted

Solution code:
def sum_count(n,s,r):
    count = 0
    if n==1:
        if (r<=s and s<=9):
            return 1
        else:
            return 0
    else:
            return sum([sum_count(n-1,s-i,i+1) for i in range(r,9)])

while True:
    n,s=map(int,raw_input().split(" "))
    if n==0 and s==0:
        break
    print sum_count(n,s,0)

Submission status: Accepted

Solution code:
def dfs(pos, t, sum):
    global cnt
    if t == n:
        if sum == s:
            cnt += 1
        return
    if pos > 9:
        return

    dfs(pos+1, t, sum)
    dfs(pos+1, t+1, sum + pos)


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

    cnt = 0
    dfs(0, 0, 0)
    print cnt

Submission status: Accepted

Solution code:

dp = [[0] * 101 for _ in range(11)]

def dfs(n, p, s):
	if p == 10:
		return
	for i in range(n, 10):
		dp[p][s + i] += 1
		dfs(i + 1, p + 1, s + i)

dfs(0, 0, 0)

while True:
	l = map(int, raw_input().split())
	if l[0] == 0 and l[1] == 0:
		break

	print dp[l[0] - 1][l[1]]

Submission status: Accepted

Solution code:
def solve(n, s, low):
    if n == 0:
        return 1 if s == 0 else 0
    res = 0
    for i in range(low,10):
        if s - i < 0: break
        res += solve(n-1, s-i, i+1)
    return res

while True:
    n, s = map(int, raw_input().split(' '))
    if n == 0: break
    print solve(n, s, 0)

Submission status: Accepted

Solution code:
def move(move_count, add, flag):
    for i in range(move_count):
        n_lis.append(num_lis[add+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count-i-1, add+i+1, flag+1)
            del n_lis[-1]
    
def calculate():
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(10,0,1)
    print count

Submission status: Accepted

Solution code:
def move(move_count, current, flag):
    for i in range(move_count):
        n_lis.append(num_lis[current+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count-i-1, current+i+1, flag+1)
            del n_lis[-1]
            
def calculate():
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(10,0,1)
    print count

Submission status: Accepted

Solution code:
def move(move_count, current, flag):
    for i in range(move_count):
        n_lis.append(num_lis[current+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count, current+i+1, flag+1)
            move_count -= 1
            del n_lis[-1]
            
def calculate():
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(10-n+1,0,1)
    print count

Submission status: Accepted

Solution code:
import itertools

l=range(10)
while 1:
    n,s=map(int, raw_input().split())
    if n==0:
        break
    cnt=0
    for i in list(itertools.combinations(l,n)):
        if sum(i)==s:
            cnt+=1
    print cnt

Submission status: Accepted

Solution code:
import itertools

while True:
	n,s = map(int,raw_input().split())
	if n == 0 and s == 0:
		break
	
	count = 0
	num = list(itertools.combinations(xrange(10), n))
	for var in num:
		if sum(var) == s:
			count += 1
	
	print count

Submission status: Accepted

Solution code:
def f(n,s,x):
  if n == s == 0:
    return 1
  elif n == 0 or x == 0:
    return 0
  else:
    a = 0
    for i in range(x):
      a += f(n-1,s-i,i)
    return a
while True:
  n,s = map(int,input().split())
  if n == s == 0:
    break
  print(f(n,s,10))

Submission status: Accepted

Solution code:
from math import *
PI = 3.1415926535898
def dfs(i, su, cnt, s):
	if su == s and cnt == 0:
		return 1
	if i == 10 or cnt == 0:
		return 0
	return dfs(i+1, su, cnt, s) + dfs(i+1, su+i, cnt-1, s)
while True:
	try:
		n, s = map(int, raw_input().strip().split())
		if n == 0 and s == 0:
			break
		print dfs(0, 0, n, s)
	except EOFError:
		break

Submission status: Accepted

Solution code:
cnt = 0
li = range(10)
n, s = 0, 0

def dfs(i, num, total):
    global cnt
    if i <= 10 and num == n and total == s:
        #answer is finded
        cnt += 1
        return;
    if i >= 10 or num > n or total > s:
        #out of range
        return;
        
    #when use i
    dfs(i+1, num+1, total+i)
    #when skip i
    dfs(i+1, num, total)
        
while True:
    n, s = map(int, raw_input().split())
    if n == s == 0:
        break
    cnt = 0
    dfs(0, 0, 0)
    print cnt

Submission status: Accepted

Solution code:
def decSum(n, sm, mn):
    #print(n,sm,mn)
    if mn + n > 10 :
        return 0
    elif sum(range(mn, mn + n)) > sm or sum(range(10 - n, 10)) < sm:
        return 0
    elif n == 1:
        return 1
    else:
        a = 0
        for i in range(mn, 10 if sm >= 10 else sm):
            a += decSum(n - 1, sm - i, i + 1)
        return a
while True:
    n, sm = map(int, input().split())
    if n == 0:
        break
    print(decSum(n, sm, 0))

Submission status: Accepted

Solution code:
#encoding=utf-8

while True:
	x, num = map(int,raw_input().split())
	if x == num == 0:
		break
	count = 0
	for a in xrange(10):
		if num == a and x == 1:
			count += 1
		if x > 1:
			for b in xrange(a + 1,10):
				if num == a+b and x == 2:
					count += 1
				if x > 2:
					for c in xrange(b + 1,10):
						if num == a+b+c and x == 3:
							count += 1
						if x > 3:
							for d in xrange(c + 1,10):
								if num == a+b+c+d and x == 4:
									count += 1
								if x > 4:
									for e in xrange(d + 1,10):
										if num == a+b+c+d+e and x == 5:
											count += 1
										if x > 5:
											for f in xrange(e + 1,10):
												if num == a+b+c+d+e+f and x == 6:
													count += 1
												if x > 6:
													for g in xrange(f + 1,10):
														if num == a+b+c+d+e+f+g and x == 7:
															count += 1
														if x > 7:
															for h in xrange(g + 1,10):
																if num == a+b+c+d+e+f+g+h and x == 8:
																	count += 1
																if x > 8:
																	for i in xrange(h + 1,10):
																		if num == a+b+c+d+e+f+g+h+i and x == 9:
																			count += 1
																			
	print count

Submission status: Accepted

Solution code:
import itertools as iter
while True:
	count = 0
	x,y = map(int,raw_input().split())
	if x == y == 0: break
	for element in iter.combinations(range(10),x):
		if sum(element) == y:
			count += 1
	print count

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import itertools

while True:
    n, s = map(int, raw_input().split())
    if n == s == 0:
        break
    count = 0
    for i in itertools.combinations(range(10), n):
        if sum(i) == s:
            count += 1
    print count

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
    n, s = map(int, input().split())
    if n == s == 0:
        break
    cnt = 0
    for x in combinations(range(10), n):
        cnt += 1 if sum(x) == s else 0
    print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools

l = range(0,10)

while True:
	cnt = 0
	a,b = map(int, raw_input().strip().split())
	if a==0 and b==0:
		break
	for elem in itertools.combinations(l, a):
		tmp = 0
		for i in xrange(0,a):
			tmp += elem[i]
		if tmp == b:
			cnt += 1
	print cnt

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)

def solve(i,wa,use):
    global ct,s,n
    if wa==s and use==n:
        ct+=1
        return
    if use>=n or i==10 or wa>s:
        return
    solve(i+1,wa,use)
    solve(i+1,wa+i,use+1)

while 1:
    n,s=map(int,raw_input().split())
    if n==0 and s==0:
        break
    ct=0
    wa=0
    solve(0,0,0)
    print ct

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)

def solve(i,wa,use):
    global ct,s,n
    if wa==s and use==n:
        ct+=1
        return
    if use>n or i==10 or wa>s:
        return
    solve(i+1,wa,use)
    solve(i+1,wa+i,use+1)

while 1:
    n,s=map(int,raw_input().split())
    if n==0 and s==0:
        break
    ct=0
    wa=0
    solve(0,0,0)
    print ct

Submission status: Accepted

Solution code:
import itertools
 
while True:
    n, s = map(int, raw_input().split())
    if (n, s) == (0, 0):
        break
    print [sum(a) for a in itertools.combinations(range(10), n)].count(s)

Submission status: Accepted

Solution code:
def f2(cnt, n, ci):
    if ci >= 10 or n > 45:
        return 0
    elif n < ci:
        return 0
    elif n == ci and cnt > 1:
        return 0
    elif n == ci and cnt == 1:
        return 1
    else:
        v = f2(cnt - 1, n - ci, ci + 1)
        v += f2(cnt, n, ci + 1)
        return v


while 1:
    n, s = map(int, input().split())
    if n == 0 and s == 0:
        break
    print(f2(n, s, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

l = list(range(10))

while True:
    n,s = list(map(int, input().split()))
    if n + s < 1:
        break
    print(len([a for a in itertools.combinations(l, n) if sum(a) == s]))

Submission status: Accepted

Solution code:
#!/usr/bin/python

import os
import sys
import itertools

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

    ans = 0
    for item in itertools.combinations(range(10), n):
        if sum(item) == s: ans += 1

    print ans

Submission status: Accepted

Solution code:
import itertools
while True:
    n, s = map(int, input().split())
    if n == s == 0:
        break
    print([sum(i) for i in itertools.combinations(range(10), n)].count(s))

Submission status: Accepted

Solution code:
import itertools

d = xrange(10)
while 1:
    n, s = map(int, raw_input().split())
    if n == 0: break
    x = map(sum, list(itertools.combinations(d, n)))
    print x.count(s)

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    print sum(sum(x)==s for x in combinations(range(10), n))

Submission status: Accepted

Solution code:
import itertools


while True:
    n, s = map(int, input().split())
    if n == s == 0:
        break
    print(sum(1 for i in itertools.combinations(range(10), n) if sum(i) == s))

Submission status: Accepted

Solution code:
import itertools

while True:
    a, b = map(int, input(). split())
    if a == 0 and b == 0:
        break

    s = list(itertools.combinations(range(10), a))

    cnt = 0

    for i in s:
        if sum(i) == b:
            cnt += 1

    print(cnt)

Submission status: Accepted

Solution code:
import itertools
Num_lis = [0,1,2,3,4,5,6,7,8,9]
while True:
    
    num = 0
   
    n,s = map(int,input().split())
    if [n,s] == [0,0]:
        break
    Con_lis = list(itertools.combinations(Num_lis, n))
    for i in range(len(Con_lis)):
        Sum = 0
        for j in range(n):
            Sum += Con_lis[i][j]
        if Sum == s:
            num += 1
    print(num)

Submission status: Accepted

Solution code:
from itertools import combinations


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

        # ????????????
        answer = 0
        combi = combinations(range(0, 10), n)
        for c in combi:
            if sum(c) == s:
                answer += 1

        # ???????????¨???
        print(answer)

Submission status: Accepted

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: Accepted

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 = []
            for i in self.Q:
                ans.append(i)
            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: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
    n, s = map(int, input().split())
    if n==s==0: break
    print([sum(c) for c in combinations(range(10), n)].count(s))

Submission status: Accepted

Solution code:
import itertools

def cal(n,s):
    l = list(itertools.combinations(range(10),n))
    count = 0
    for i in l:
        if sum(i) == s:
            count += 1
    return count

while True:
    n,s = map(int,input().split())
    if n == 0 and s==0:
        break
    else:
        print(cal(n,s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def to_i(e):
  return int(e)

def solve(n,s,a):
  if n == 1:
    if s>=a and s<=9:
      return 1
    else:
      return 0
  result = 0
  for i in xrange(a, s-a):
    result += solve(n-1, s-i, i+1)
  return result

while True:
  line = sys.stdin.readline()
  if line == "0 0\n": break
  l = map(to_i, line.rstrip().split(" "))
  n = l[0]
  s = l[1]
  print solve(n,s,0)

Submission status: Accepted

Solution code:
def solve(n,s,lst):
    if n == 0 and s == 0:
        #print("Complete!")
        return(1)
    elif n==0 or len(lst)==0 or s < 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(10))))
            
        if n==0 and s==0:
            break

Submission status: Accepted

Solution code:
def dfs(i,ls):
    if i == 10:
        return len(ls) == n and sum(ls) == s
    return dfs(i + 1,ls) + dfs(i + 1,ls + [i])

while True:
    n,s = map(int,input().split())
    if n == 0:
        break
    print(dfs(0,[]))

Submission status: Accepted

Solution code:
def dfs(s, l, n):
    '''
    l?????????????????°??????n???????????§s????????????????????????????????°
    '''
    if s < 0:
        return 0
    elif n == 0:
        if s == 0:
            return 1
        else:
            return 0
    else:
        return sum([dfs(s-l[i], l[i+1:], n-1) for i in range(len(l))])

nl, sl = [], []
while True:
    n, s = map(int, input().split())
    if s == 0 and n == 0:
        break
    nl.append(n)
    sl.append(s)

for n, s in zip(nl, sl):
    print(dfs(s, list(range(10)), n))

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
    n,s = map(int, input().split())
    if n==0:
        break
    ctr=0
    for cmb in combinations(range(10), n):
        if sum(cmb)==s : ctr += 1
    print(ctr)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import datetime
from itertools import combinations

for s in sys.stdin:
    n, s = map(int, s.split())
    if n == 0:
        break

    cnt = 0
    for x in combinations(range(10), n):
        if sum(x) == s:
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

import math

def minmax_n(n):
    return sum(i for i in range(0,n)), sum(i for i in range(9,9-n,-1))

def saiki(n, s, ls):
    ans = 0
    if n==1:
        if s in ls:
            return 1
        else:
            return 0
    if s < minmax_n(n)[0] or s > minmax_n(n)[1]:
        return 0
    for l in ls:
        ls_ = ls[:]
        ls_.remove(l)
        ans += saiki(n-1, s-l, ls_)
    return ans

while(1):
    str = raw_input()
    n, s = map(int, str.split(' '))
    
    if n==0 and s==0:
        break
    if s < minmax_n(n)[0] or s > minmax_n(n)[1]:
        print 0
    else:
        print saiki(n, s, range(10))/math.factorial(n)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations as c
for line in sys.stdin:
    count = 0
    k, v = map(int, line.split())
    if k or v:
        for i in c(range(10), k):
            if sum(i) == v:
                count += 1
    else:
        break
    print(count)

Submission status: Accepted

Solution code:
a = [0,1,2,3,4,5,6,7,8,9]

wa_lis = []
num = 0
def wa(n,k,m):
    global num

    if n == 10 and m == 0 and k == 0:
        num += 1
    if n == 10:
        return
    return wa(n + 1,k - a[n],m - 1) or wa(n+1,k,m)

while True:
   
    n,s = map(int,input().split())
    if [n,s] == [0,0]:
        break
    wa(0,s,n)
    print(num)
    num = 0

Submission status: Accepted

Solution code:
s = 0
comb = 0

def main():
    global s, comb

    while True:
        n, s = map(int, input().split())
        if n == 0 and s == 0:
            break

        comb = 0
        dfs(0, n, 0)
        print(comb)


def dfs(i, num_count, current_sum):
    global comb
    if num_count == 0 and current_sum == s:
        comb += 1
        return
    if i > 9:
        return

    dfs(i + 1, num_count, current_sum)
    dfs(i + 1, num_count - 1, current_sum + i)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# Aizu Problem 0030: Sum of Integers
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

def dfs(pos, t, sum):
    global cnt
    if t == n:
        if sum == s:
            cnt += 1
        return
    if pos > 9:
        return
 
    dfs(pos+1, t, sum)
    dfs(pos+1, t+1, sum + pos)
 
 
while True:
    n, s = [int(_) for _ in input().split()]
    if n == s == 0:
        break
    cnt = 0
    dfs(0, 0, 0)
    print(cnt)

Submission status: Accepted

Solution code:
def dfs(depth,s,m):
    global maxdepth,target,cnt
    if depth==maxdepth:
        if s==target:
            cnt+=1
        return
    r=min([target-s,9])+1
    for i in range(r):
        if i>m:
            dfs(depth+1,s+i,i)
while 1:
    maxdepth,target=[int(st)for st in input().split(" ")]
    if maxdepth==target==0:break
    cnt=0
    u=[False for i in range(10)]
    dfs(0,0,-1)
    print(cnt)

Submission status: Accepted

Solution code:
# 0030
import itertools
while True:
    n, s = map(int, input().split())
    if n == s == 0: break
    c = itertools.combinations(range(10), n)
    print(len(list(filter(lambda c: sum(c) == s, c))))

Submission status: Accepted

Solution code:
def calc_combination(n, s, max_digit):
    if n == 1:
        if max_digit < s:
            return 0
        else:
            return 1
    if n * (n - 1) / 2 > s:
        return 0
    total = 0
    max_digit = min(s, max_digit)
    for i in range(n-1, max_digit+1):
        total += calc_combination(n-1, s-i, i-1)
    return total

while True:
    n, s = map(int, input().split())
    if n == s == 0:
        break
    print(calc_combination(n, s, 9))

Submission status: Accepted

Solution code:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import itertools

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    L = [i for i in xrange(10)]
    cnt = 0
    for i in itertools.combinations(L, n):
        if sum(i) == s:
            cnt += 1
    print cnt

Submission status: Accepted

Solution code:
import itertools
while True:
    n,s = map(int, input().split())
    if not(n or s):
        break
    t = 0
    for i in itertools.combinations(range(0,10), n):
        if sum(i) == s:
            t += 1
    print(t)

Submission status: Accepted

Solution code:
import itertools

while True:
    n, s = map(int, input().split())
    count = 0
    if n == 0:
        break
    for c in itertools.combinations([i for i in range(10)], n):
        if sum(c) == s:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
def search(N, s, start, depth):
    if depth == 0 and s == 0:
        return 1
    if depth == 0 and s != 0:
        return 0

    ans = 0
    for i in range(start, 10):
        if N[i] == 1:
            N[i] = 0
            ans += search(N, s-i, i, depth-1)
            N[i] = 1
    return ans

n,s = [int(i) for i in input().split()]
while n != 0 or s != 0:

    N = [1 for i in range(10)]
    print(search(N, s, 0, n))

    n,s = [int(i) for i in input().split()]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inputcase():
	global n,s
	n,s = map(int,input().split())
	return n!=0 or s!=0

memo = [[[0 for j in range(123)] for i in range(11)] for k in range(11)]
done = [[[False for j in range(123)] for i in range(11)] for k in range(11)]

def dfs(k, l, t):
	if t < 0:
		return 0
	elif k == 0 and t > 0:
		return 0
	elif k == 0:
		return 1
	elif l > 9:
		return 0
	if done[k][l][t]:
		return memo[k][l][t]
	done[k][l][t] = True
	for i in range(l,10):
		memo[k][l][t] += dfs(k-1,i+1,t-i)
	return memo[k][l][t]

while inputcase():
	print(dfs(n,0,s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
for e in iter(input,'0 0'):
 n,s=map(int,e.split())
 print(sum(s==sum(p)for p in itertools.combinations(range(10),n)))

Submission status: Accepted

Solution code:
import itertools
r=[]
while 1:
    a=list(map(int,input().split()))
    if not a[0] and not a[1]:break
    r.extend([sum([1 for i in itertools.combinations(range(10),a[0]) if sum(i)==a[1]])])
[print(i) for i in r]

Submission status: Accepted

Solution code:
#!/usr/bin/env python

while True:
	n, s = map(int, raw_input().split())
	if not n:
		break
	ans = 0
	for i in range(2**10):
		cnt = 0
		ss = 0
		for j in range(10):
			if i & (2 ** j):
				cnt += 1
				ss += j
		if cnt == n and ss == s:
			ans += 1
	print(ans)

Submission status: Accepted

Solution code:
#rest...使用数の残り
#n...今見る数字
#acc...今までの合計
#to...目的の値

def counter(rest, n, acc, to):
  #残り使用数が0なら...acc == to -> 1,  acc != to -> 0
  if rest == 0:
    return acc == to

  #nが使える数(9)を超えたら終了
  if n == 10:
    return 0
  
  #nを使った場合と使わなかった場合の合計の数を出力
  return counter(rest - 1, n + 1, acc + n , to) + counter(rest, n + 1, acc, to)

while True:
  n, s = map(int, input().split())

  if not n:
    break

  print(counter(n, 0, 0, s))

Submission status: Accepted

Solution code:
from itertools import combinations
import sys

for n, s in (map(int, l.split()) for l in sys.stdin.readlines()):
    if n == 0: break
    print(sum(1 for a in combinations(range(10), n) if sum(a)==s))

Submission status: Accepted

Solution code:
# AOJ 0030 Sum of Integers
# Python3 2018.6.18 bal4u

def rec(n, s, vmin):
	if vmin == 10 or vmin > s: return 0
	if n == 1: return (1 if s < 10 else 0)
	sum = 0;
	for i in range(vmin, 10): sum += rec(n-1, s-i, i+1)
	return sum

while True:
	n, s = list(map(int, input().split()))
	if n < 1: break
	print(rec(n, s, 0))

Submission status: Accepted

Solution code:
def dfs(i,step,remain):
    if remain<0 or step<0 or i<-1:return 0
    if remain==0 and step==0:return 1
    return dfs(i-1,step-1,remain-i)+dfs(i-1,step,remain)
while True:
    n,s=map(int,raw_input().split())
    if(n==0 and s==0):break
    print dfs(9,n,s)

Submission status: Accepted

Solution code:
table={}
def memorize(f):
    global table
    def func(*args):
        if not args in table:
            table[args]=f(*args)
        return table[args]
    return func
@memorize
def dfs(i,step,remain):
    if remain<0 or step<0 or i<-1:return 0
    if remain==0 and step==0:return 1
    return dfs(i-1,step-1,remain-i)+dfs(i-1,step,remain)
while True:
    n,s=map(int,raw_input().split())
    if(n==0 and s==0):break
    print dfs(9,n,s)

Submission status: Accepted

Solution code:
def dfs(n, sum ,depth):
    if(depth == 0):
        return int(sum == s)
    else:
        count = 0
        for i in xrange(n+1,10):
            count += dfs(i, sum+i, depth-1)
        return count

while True:
    (n, s) = [int(i) for i in raw_input().split()]
    if((0,0) == (n,s)):
        break
    print dfs(-1,0,n)

Submission status: Accepted

Solution code:
import sys
import itertools
def solve(x,n,s):
    t=[c for c in itertools.combinations(x,n) if sum(c)==s]
    return len(t)

x=[i for i in range(10)]
for line in sys.stdin.readlines():
    n,s=map(int, line.rstrip().split())
    if s|n==0: break
    print solve(x,n,s)

Submission status: Accepted

Solution code:
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin
from itertools import combinations

for line in stdin:
    if line.startswith('0 0'):
        break
    num, ans = (int(s) for s in line.split())
    print(sum(sum(t) == ans for t in combinations(xrange(10), num)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from itertools import combinations
import operator as op

nums = range(0, 10)
while True:
    n, s = map(int, raw_input().split())
    if (n, s) == (0, 0): break
    count = 0
    for c in combinations(nums, n):
        if sum(c) == s:
            count += 1
    print count

Submission status: Accepted

Solution code:
def dec2bin(n, base=10):
    s=""
    x="01"
    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
    if s>=50: print 0
    else: print x[n][s]

Submission status: Accepted

Solution code:
import itertools

while True:
    n, s = map(int, raw_input().split())
    if (n, s) == (0, 0):
        break
    print [sum(a) for a in itertools.combinations(range(10), n)].count(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

n = 0
s = 0

def combination(n, k):
    max = 2 ** n

    for i in xrange(max):
        result = [0] * n
        for j in xrange(n):
            result[j] = i >> j & 1
        cnt = 0
        for b in result:
            if b == 1:
                cnt += 1
        if cnt == k:
            yield result


for line in sys.stdin:
    l = map(int, line.strip().split())
    n = l[0]
    s = l[1]

    if n == 0 and s == 0:
        break

    ans = 0

    for ar in combination(10, n):
        sm = 0
        for i in xrange(len(ar)):
            if ar[i] == 1:
                sm += i

        if sm == s:
            ans += 1

    print ans