Problem:
Problem A: Equal Sum Sets Let us consider sets of positive integers less than or equal to n . Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set elements and their sum to be k and s , respectively, sets satisfying the conditions are limited. When n = 9, k = 3 and s = 23, {6, 8, 9} is the only such set. There may be more than one such set, in general, however. When n = 9, k = 3 and s = 22, both {5, 8, 9} and {6, 7, 9} are possible. You have to write a program that calculates the number of the sets that satisfy the given conditions. Input The input consists of multiple datasets. The number of datasets does not exceed 100. Each of the datasets has three integers n , k and s in one line, separated by a space. You may assume 1 ≤ n ≤ 20, 1 ≤ k ≤ 10 and 1 ≤ s ≤ 155. The end of the input is indicated by a line containing three zeros. Output The output for each dataset should be a line containing a single integer that gives the number of the sets that satisfy the conditions. No other characters should appear in the output. You can assume that the number of sets does not exceed 2 31 - 1. Sample Input 9 3 23
9 3 22
10 3 28
16 10 107
20 8 102
20 10 105
20 10 155
3 4 3
4 2 11
0 0 0 Output for the Sample Input 1
2
0
20
1542
5448
1
0
0

Solution (Python):
def dfs(v, k, s):
    if k == K:
        return 1 if s == S else 0
    res = 0
    for i in range(v + 1, N + 1):
        res += dfs(i, k + 1, s + i)
    return res

while True:
    N, K, S = map(int, input().split())
    if not N:
        break
    print(dfs(0, 0, 0))

Solution (Python):



import os
import sys
import itertools
import math
from collections import Counter, defaultdict

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

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n, k, s = map(int, raw_input().split())
            if (n, k, s) == (0, 0, 0):
                break
            ans = 0
            for elem in itertools.combinations(range(1, n+1), k):
                if sum(elem) == s:
                    ans += 1
            print ans
                    
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Solution (Python):
def dfs(i,k,s):
    if k == s == 0: return 1
    if i > n: return 0
    if k > 0 and s <= 0: return 0
    if k == 0 and s != 0 or s < sum(i+j for j in range(k)): return 0
    return dfs(i+1,k,s)+dfs(i+1,k-1,s-i)

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

    print dfs(1,k,s)

Solution (Python):
def dfs(i,k,s):
    if k == s == 0: return 1
    if i > n or s < i*k+k-1: return 0
    return dfs(i+1,k,s)+dfs(i+1,k-1,s-i)
 
while 1:
    n,k,s = map(int,raw_input().split())
    if n == 0: break
    print dfs(1,k,s)

Solution (Python):
import itertools
while 1:
    n,k,s = map(int,raw_input().split())
    if n == 0: break
    print sum(sum(ele) == s for ele in itertools.combinations(range(1,n+1),k))

Solution (Python):



from itertools import combinations

while True:
    n,k,s = map(int,input().split(" "))
    if n == 0 and k == 0 and s == 0:
        break
    print(sum([1 if sum(t) == s else 0 for t in combinations(range(1,n+1),k)]))

Solution (Python):
while 1:
	n, k, s = map(int,raw_input().split())
	if (n, k, s) == (0, 0, 0):
		break
	dp = [[0 for i in range(s)] for j in range(k)]
	ub = min(n+1,s+1)
	for x in range(1,ub):
		for j in range(k-1):
			for i in range(s-x):
				if dp[j+1][i] >= 1:
					dp[j][i+x] += dp[j+1][i]
		dp[k-1][x-1] = 1
	print dp[0][s-1]

Solution (Python):



def rec(csum, chi, cval):
    global n
    global k 
    global s 
    global cnt
    if chi == k:
        if csum != s:
            return
        elif csum == s:
            cnt += 1
            return
    elif chi < k:
        for i in range(cval+1, n+1):
            if csum+i > s:
                return
            else:
                rec(csum+i, chi+1, i)

(n, k, s) = map(int, raw_input().split())
while n!=0:
    cnt = 0
    rec(0, 0, 0)
    print cnt

    (n, k, s) = map(int, raw_input().split())

Solution (Python):
import itertools

while True:
    N, K, S = map(int, input().split())
    if N == K == S == 0:
        break
    ans = 0
    for l in itertools.combinations(range(1, N+1), K):
        if sum(l) == S:
            ans += 1
    print(ans)

Solution (Python):
import itertools

while True:
    N, K, S = map(int, input().split())
    if N == K == S == 0:
        break
    print(sum(1 for l in itertools.combinations(range(1, N+1), K) if sum(l) == S))

Solution (Python):
import itertools
while True:
    N, K, S = map(int, input().split())
    if not N: break
    print(sum(sum(l) == S for l in itertools.combinations(range(1, N+1), K)))

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

Solution (Python):
from itertools import combinations as c
while True:
    n,k,s= map(int, input().split())
    if n==0: break
    print(sum(1 for l in list(c(range(1,n+1),k)) if sum(l)==s))

Solution (Python):
import itertools

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

  a = itertools.combinations(range(1, n + 1), k)

  ans = 0

  for e in a:
    if sum(e) != s:
      continue
    ans += 1

  print(ans)

Solution (Python):
import itertools
while True:
    N,K,S = map(int,input().split())
    if N == 0: break
    cnt = 0
    for comb in itertools.combinations(range(1,N+1),K):
        if sum(comb) == S:
            cnt += 1
    print(cnt)

Solution (Python):
def rec(n, u, k, s):
    if k == 1:
        if u < s <= n:
            return 1
        else:
            return 0

    ret = 0
    for i in range(u + 1, n - k + 2):
        ret += rec(n, i, k - 1, s - i)

    return ret

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

    print(rec(n, 0, k, s))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,k,s = LI()
        if n == 0 and k == 0 and s == 0:
            break
        d = collections.defaultdict(int)
        d[(0,0)] = 1
        for i in range(1,n+1):
            for kk,vv in list(d.items()):
                if kk[0] == k or kk[1] + i > s:
                    continue
                d[(kk[0]+1,kk[1]+i)] += vv

        rr.append(d[(k,s)])

    return '\n'.join(map(str, rr))


print(main())

Solution (Python):
from itertools import combinations
while 1:
    n,k,s=map(int,input().split())
    if n==k==s==0:break
    a=0
    for i in combinations(range(1,n+1),k):
        if len(set(i))<k:continue
        a+=sum(i)==s
    print(a)

Solution (Python):
memo = {}
def dfs(N, K, S):
    key = (N, K, S)
    if key in memo:
        return memo[key]
    if N == 0:
        return S == K == 0
    r = dfs(N-1, K, S)
    if S >= N:
        r += dfs(N-1, K-1, S-N)
    memo[key] = r
    return r

ans = []
while 1:
    N, K, S = map(int, input().split())
    if N == 0:
        break
    ans.append(dfs(N, K, S))
print(*ans, sep='\n')