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: Wrong Answer

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

import os
import sys

class Hoge(object):
    
    def __init__(self):
        pass

    def func(self):
        '''
        insert your code
        '''
        while True:
            n, s = map(int, raw_input().split())
            if n == 0 and s == 0:
                break
            self.ans = 0
            # self.dfs(0, 0, [], n, s)
            for i in range(s):
                for j in range(s):
                    for k in range(s):
                        if i == j or j == k or k == i:
                            continue
                        else:
                            if i + j + k == s:
                                # print i, j, k
                                self.ans += 1
                
            print self.ans / 3
        return None

    def dfs(self, num, sumNum, rec, n, s):
        print num, sumNum, rec, n, s
        if num == n:
            if sumNum == s:
                self.ans += 1
        else:
            for i in range(s):
                if not i in rec and sumNum + i <= s:
                    self.dfs(num + 1, sumNum + i, rec + [i], n, s)

if __name__ == '__main__':
    h = Hoge()
    h.func()

Submission status: Wrong Answer

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

import os
import sys

class Hoge(object):
    
    def __init__(self):
        pass

    def func(self):
        '''
        insert your code
        '''
        while True:
            n, s = map(int, raw_input().split())
            if n == 0 and s == 0:
                break
            self.ans = 0
            # self.dfs(0, 0, [], n, s)
            for i in range(s+1):
                for j in range(s+1):
                    for k in range(s+1):
                        if i >= j or j >= k or i >= k:
                            continue
                        else:
                            if i + j + k == s:
                                print i, j, k
                                self.ans += 1
                
            print self.ans
        return None

    def dfs(self, num, sumNum, rec, n, s):
        print num, sumNum, rec, n, s
        if num == n:
            if sumNum == s:
                self.ans += 1
        else:
            for i in range(s):
                if not i in rec and sumNum + i <= s:
                    self.dfs(num + 1, sumNum + i, rec + [i], n, s)

if __name__ == '__main__':
    h = Hoge()
    h.func()

Submission status: Wrong Answer

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

import os
import sys

class Hoge(object):
    
    def __init__(self):
        pass

    def func(self):
        '''
        insert your code
        '''
        while True:
            n, s = map(int, raw_input().split())
            if n == 0 and s == 0:
                break
            self.ans = 0
            # self.dfs(0, 0, [], n, s)
            for i in range(s+1):
                for j in range(s+1):
                    for k in range(s+1):
                        if i >= j or j >= k or i >= k:
                            continue
                        else:
                            if i + j + k == s:
                                # print i, j, k
                                self.ans += 1
                
            print self.ans
        return None

    def dfs(self, num, sumNum, rec, n, s):
        print num, sumNum, rec, n, s
        if num == n:
            if sumNum == s:
                self.ans += 1
        else:
            for i in range(s):
                if not i in rec and sumNum + i <= s:
                    self.dfs(num + 1, sumNum + i, rec + [i], n, s)

if __name__ == '__main__':
    h = Hoge()
    h.func()

Submission status: Wrong Answer

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

import os
import sys

class Hoge(object):
    
    def __init__(self):
        pass

    def func(self):
        '''
        insert your code
        '''
        while True:
            n, s = map(int, raw_input().split())
            if n == 0 and s == 0:
                break
            self.ans = 0
            # self.dfs(0, 0, [], n, s)
            for i in range(s):
                for j in range(s):
                    for k in range(s):
                        if i >= j or j >= k or i >= k:
                            continue

                        if i + j + k == s:
                            # print i, j, k
                            self.ans += 1
                
            print self.ans
        return None

    # def dfs(self, num, sumNum, rec, n, s):
    #     print num, sumNum, rec, n, s
    #     if num == n:
    #         if sumNum == s:
    #             self.ans += 1
    #     else:
    #         for i in range(s):
    #             if not i in rec and sumNum + i <= s:
    #                 self.dfs(num + 1, sumNum + i, rec + [i], n, s)

if __name__ == '__main__':
    h = Hoge()
    h.func()

Submission status: Wrong Answer

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

import os
import sys

class Hoge(object):
    
    def __init__(self):
        pass

    def func(self):
        '''
        insert your code
        '''
        while True:
            n, s = map(int, raw_input().split())
            if n == 0 and s == 0:
                break
            self.ans = 0
            # self.dfs(0, 0, [], n, s)
            for i in range(10):
                for j in range(10):
                    for k in range(10):
                        if i >= j or j >= k or i >= k:
                            continue

                        if i + j + k == s:
                            # print i, j, k
                            self.ans += 1
                
            print self.ans
        return None

    # def dfs(self, num, sumNum, rec, n, s):
    #     print num, sumNum, rec, n, s
    #     if num == n:
    #         if sumNum == s:
    #             self.ans += 1
    #     else:
    #         for i in range(s):
    #             if not i in rec and sumNum + i <= s:
    #                 self.dfs(num + 1, sumNum + i, rec + [i], n, s)

if __name__ == '__main__':
    h = Hoge()
    h.func()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def main():
    while True:
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            break
        c = 0
        for i in range(b // 2):
            for j in range(i + 1, b):
                for k in range(j + 1, b):
                    if i + j + k == b:
                        c += 1
        print(c)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n,s = map(int,raw_input().split())
    except EOFError:
        break
    if (n,s) == (0,0):
        break
    
    if s == 0 or s == 1 or s == 2:
        print 0
    else:    
        ls = []
        for k in range(s):
            for l in range(1,s):
                if k + l > s:
                    break
                for m in range(2,s):
                    tmp = k + l + m
                    if tmp == s and k!=l and l!=m and m!=k:
                        tmp2 = tuple(sorted((k,l,m)))
                        ls.append(tmp2)
                        break
        print len(set(ls))

Submission status: Wrong Answer

Solution code:
def sum_count(n,s,r):
    if n==0 and s==0:
        return 1
    if n<=0 or s<0:
        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: Wrong Answer

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: Wrong Answer

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,10):
										if num == a+b+c+d+e and x == 5:
											count += 1
										if x > 5:
											for f in xrange(10):
												if num == a+b+c+d+e+f and x == 6:
													count += 1
												if x > 6:
													for g in xrange(10):
														if num == a+b+c+d+e+f+g and x == 7:
															count += 1
														if x > 7:
															for h in xrange(10):
																if num == a+b+c+d+e+f+g+h and x == 8:
																	count += 1
																if x > 8:
																	for i in xrange(10):
																		if num == a+b+c+d+e+f+g+h+i and x == 9:
																			count += 1
																			
	print count

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)

def solve(i,wa,use):
    global ct,s,n
    if use>n:
        return
    if i==11:
        return
    if wa==s and use==n:
        ct+=1
        return
    if wa>=s:
        return
    if wa<s:
        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: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)

def solve(i,wa,use):
    global ct,s,n
    if use>n:
        return
    if i==11:
        return
    if wa==s and use==n:
        ct+=1
        return
    if wa>s:
        return
    if wa<s:
        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: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)

def solve(i,wa,use):
    global ct,s,n

    if use>n:
        return
    if i==11:
        return
    if wa==s and use==n:
        ct+=1
        return
    if wa>=s:
        return
    if wa<s:
        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: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)

def solve(i,wa,use):
    global ct,s,n

    if use>n or i==10 or wa>s:
        return
    if wa==s and use==n:
        ct+=1
        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: Wrong Answer

Solution code:
def f2(cnt, n, ci):
    if 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


n, s = map(int, input().split())
print(f2(n, s, 0))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import os
import sys
import itertools

def solve(f):
    while True:
        n, s = f.read_int_list()
        if n == 0 and s == 0: break

        if s > 45: return 0

        def dfs(num, l):
            if num == 0:
                return 1 if len(l) == n else 0
            res = 0
            for i in xrange(10):
                if (len(l) == 0) or (max(l) < i and i <= num):
                    li = l.copy()
                    li.add(i)
                    res += dfs(num-i, li)
            return res

        print dfs(s, set())

class Reader(object):
    def __init__(self, filename=None):
        self.test_mode = filename is not None
        self.cases = 1
        self.buffer = []
        if self.test_mode:
            with open(filename) as f:
                blank_flg = False
                for line in f:
                    line = line.strip()
                    if line:
                        self.buffer.append(line)
                        blank_flg = False
                    else:
                        if not blank_flg: self.cases += 1
                        blank_flg = True

    def __readline(self):
        return self.buffer.pop(0) if self.test_mode else raw_input()

    def read_int(self):
        return int(self.__readline())
    def read_float(self):
        return float(self.__readline())
    def read_long(self):
        return long(self.__readline())
    def read_str(self):
        return self.__readline()

    def read_int_list(self):
        return [int(item) for item in self.__readline().split()]
    def read_float_list(self):
        return [float(item) for item in self.__readline().split()]
    def read_long_list(self):
        return [long(item) for item in self.__readline().split()]
    def read_str_list(self):
        return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv)>1 else None
    f = Reader(filename)
    solve(f)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import os
import sys
import itertools

def solve(f):
    while True:
        n, s = f.read_int_list()
        if n == 0 and s == 0: break

        if s > 45:
            print 0
            continue

        def dfs(num, l):
            if num == 0:
                return 1 if len(l) == n else 0
            res = 0
            for i in xrange(10):
                if (len(l) == 0) or (max(l) < i and i <= num):
                    li = l.copy()
                    li.add(i)
                    res += dfs(num-i, li)
            return res

        print dfs(s, set())

class Reader(object):
    def __init__(self, filename=None):
        self.test_mode = filename is not None
        self.cases = 1
        self.buffer = []
        if self.test_mode:
            with open(filename) as f:
                blank_flg = False
                for line in f:
                    line = line.strip()
                    if line:
                        self.buffer.append(line)
                        blank_flg = False
                    else:
                        if not blank_flg: self.cases += 1
                        blank_flg = True

    def __readline(self):
        return self.buffer.pop(0) if self.test_mode else raw_input()

    def read_int(self):
        return int(self.__readline())
    def read_float(self):
        return float(self.__readline())
    def read_long(self):
        return long(self.__readline())
    def read_str(self):
        return self.__readline()

    def read_int_list(self):
        return [int(item) for item in self.__readline().split()]
    def read_float_list(self):
        return [float(item) for item in self.__readline().split()]
    def read_long_list(self):
        return [long(item) for item in self.__readline().split()]
    def read_str_list(self):
        return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv)>1 else None
    f = Reader(filename)
    solve(f)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

Submission status: Wrong Answer

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

str = raw_input()
n, s = map(int, str.split(' '))

if n==0 and s==0:
    exit()
if s < minmax_n(n)[0] or s > minmax_n(n)[1]:
    print 0
print saiki(n, s, range(10))/math.factorial(n)

Submission status: Wrong Answer

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 and v:
        for i in c(range(10), k):
            if sum(i) == v:
                count += 1
    else:
        break
    print(count)

Submission status: Wrong Answer

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 == 9 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: Wrong Answer

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):
        total += calc_combination(n-1, s-i, max_digit-1)
    return total

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

Submission status: Wrong Answer

Solution code:
while 1:
 n,x=map(int,input().split())
 if n+x==0:break
 print(sum([max(0,(x-a-1)//2-max(a,x-a-1-n))for a in range(1,x//3)]))

Submission status: Wrong Answer

Solution code:

import itertools

while True:
    try:
        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

    except ValueError:
        break

Submission status: Wrong Answer

Solution code:
def ksubset(n, k, i, ans):
    global cnt;
    if k == 0:
        if ans==s:
            cnt+=1
        return
    if n == 0:
        return
    ksubset(n-1, k-1, i+1, ans+i)
    ksubset(n-1, k, i+1, ans)


temp=raw_input()
s=int(temp.split()[1])
n=int(temp.split()[0])
while (s<>0) and (n<>0):
    cnt=0    
    ksubset(10,n,0,0)
    print cnt
    temp=raw_input()
    s=int(temp.split()[1])
    n=int(temp.split()[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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==0: break
    print solve(x,n,s)

Submission status: Wrong Answer

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(9), num)))

Submission status: Wrong Answer

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(9, n):
        sm = 0
        for i in xrange(len(ar)):
            if ar[i] == 1:
                sm += i

        if sm == s:
            ans += 1

    print ans

Submission status: Wrong Answer

Solution code:

def dfs(n, m, s):
  if n == N:
    return 1 if s == S else 0
  ans = 0
  for i in range(m, 11 - n):
    ans += dfs(n + 1, i + 1, s + i)
  return ans;

while 1:
  N, S = map(int, raw_input().split())
  if not N:
    break
  print dfs(0, 0, 0)

Submission status: Wrong Answer

Solution code:
def f(mn, n, sm):
    if n == 0 and sm == 0:
        return 1
    if mn == 10 or n == 0 or sm == 0:
        return 0
    ct = 0
    for i in range(mn, min(10, sm + 1)):
        ct += f(i + 1, n - 1, sm - i)
    return ct

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

Submission status: Wrong Answer

Solution code:
def count(target, max_size, c_size, c_num, sum):
  if max_size == c_size:
    return 1 if sum == target else 0

  ans = 0
  for i in range(c_num, 10):
    ans += count(target, max_size, c_size+1, i+1, sum+i)
  return ans

import sys
for s in sys.stdin:
  max_size, target = map(int, s.split())
  if target == 0 or max_size == 0: break
  ans = count(target, max_size, 0, 0, 0)
  print ans

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
while True:
    n,s=map(int,input().split())
    if n==0 and s==0:
        break
    num=[i for i in range(0,s+1)]
    print(num)
    ans=0
    comb=itertools.combinations(num,n)
    for c in comb:
        if sum(c) == s:
            ans +=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
while True:
    n,s=map(int,input().split())
    if n==0 and s==0:
        break
    num=[i for i in range(0,s+1)]
    ans=0
    comb=itertools.combinations(num,n)
    for c in comb:
        if sum(c) == s:
            ans +=1
    print(ans)

Submission status: Time Limit Exceeded

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

def kai(n):
    s=n
    ans=1
    while s>1:
        ans*=s
        s-=1
    return ans

def main():
    LIST=[]

    while True:
        try:
            LIST=[]
            ans=0
            
            n,s=map(int,input().split())
            if n==0:
                break       #N=0なら終了

            for i in range(n):
                LIST.append(0)

            for j in range(10**n):
                index=0
                up=True
                flag=False
                count=0     #初期化

                for i in LIST:
                    if LIST.count(i)>1:
                        flag=True   #同一の数字が無いか検索

                if flag:
                    pass    #あったら飛ばす
                else:
                    for i in LIST:
                        count+=i
                    if count==s:
                        ans+=1      #無かったら合計値が合うか見る

                while up:
                    LIST[index]+=1
                    if LIST[index]%10==0:
                        LIST[index]=0
                        up=True
                        index+=1
                    else:
                        up=False
                    if index==len(LIST):
                        break


            print(int(ans/kai(n)))

        except EOFError:
            break

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def f2(cnt, n, ci):
    if 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: Time Limit Exceeded

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
                print(c)
            for i in range(max(c), self.s+1):
                if i not in c and 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: Time Limit Exceeded

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
                print(c)
            for i in range(self.s-max(c) + 1):
                if max(c)<i and 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: Time Limit Exceeded

Solution code:
def div(n,m):
    try:
        return n/m
    except ZeroDivisionError:
        return 0
def degit(n, m):
    r = []
    b = -1
    for i in xrange(m):
        s = div(n%(10**(i+1)),(10**i))
        if(b<s):
            b = s
            r.append(s)
    if(len(r) == m):
        return r
while True:
    (n, s) = [int(i) for i in raw_input().split()]
    if((0,0) == (n,s)):
        break
    ans = 0
    for i in xrange(10**n):
        r = degit(i,n)
        if(r==None):
            continue
        if(len(r)!=len(list(set(r)))):
            continue
        if(reduce(lambda x,y:x+y,r) == s):
            ans += 1
    print ans

Submission status: Memory Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

S = []
N = []
while True:
    n,s = map(int,input().split(" "))
    if s == 0 and n == 0:
        break
    else:
        N.append(n)
        S.append(s)

for i in range(0,len(S)):
    sumMap = list(map(sum,list(itertools.combinations(range(0,S[i]+1),N[i]))))
    print(sum([1 for j in range(0,len(sumMap)) if sumMap[j] == S[i]]))

Submission status: Memory Limit Exceeded

Solution code:
from itertools import combinations as C

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

    print([sum(c) == s for c in C(range(s+1), n)])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

Solution code:
ans = 0
def count(use, sum, n, s):
    global ans
    if(sum > s or n < 0):
        return;
    if(n == 0 and s == sum):
        ans += 1
    else:
        for i in range(use + 1, 10):
            count(i, sum + i, n - 1, s)

while(True):
    n = map(int, raw_input().split())
    ans = 0
    if(n[0] == 0 and n[1] == 0):
        break
    count(-1, 0, n[0], n[1])
    print(ans)

Submission status: Accepted

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

import sys
import itertools

for s in sys.stdin:
  d = map( int, s.split() )
  if d == [ 0,0 ]:
    break
  n, s = d[0], d[1]
  lis = list(itertools.combinations(range(10),d[0]))
  print sum( [ 1 for e in lis if sum(e) == d[1] ] )

Submission status: Accepted

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

import os
import sys
import itertools

class Hoge(object):
    
    def __init__(self):
        pass

    def func(self):
        '''
        insert your code
        '''
        while True:
            n, s = map(int, raw_input().split())
            if n == 0 and s == 0:
                break
            ans = 0
            # self.dfs(0, 0, [], n, s)
            # for i in range(10):
            #     for j in range(10):
            #         for k in range(10):
            #             if i >= j or j >= k or i >= k:
            #                 continue

            #             if i + j + k == s:
            #                 print i, j, k
            #                 ans += 1
            for e in itertools.combinations(range(10), n):
                if sum(e) == s:
                    ans += 1
                
            print ans
        return None

    # def dfs(self, num, sumNum, rec, n, s):
    #     print num, sumNum, rec, n, s
    #     if num == n:
    #         if sumNum == s:
    #             self.ans += 1
    #     else:
    #         for i in range(s):
    #             if not i in rec and sumNum + i <= s:
    #                 self.dfs(num + 1, sumNum + i, rec + [i], n, s)

if __name__ == '__main__':
    h = Hoge()
    h.func()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

S = []
N = []
while True:
    n,s = map(int,input().split(" "))
    if s == 0 and n == 0:
        break
    else:
        N.append(n)
        S.append(s)

for i in range(0,len(S)):
    sumMap = list(map(sum,list(itertools.combinations(range(0,10),N[i]))))
    print(sum([1 for j in range(0,len(sumMap)) if sumMap[j] == S[i]]))

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

import itertools

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