Find the number of ways of distributing N objects into R groups such that each group…
- User
Find the number of ways of distributing N objects into R groups such that each group gets 1 or more objects. Input: The one and only line of input contains two numbers separated by a single space, which are N and R respectively.
Output: The corresponding answer modulo 10000007 in a single line and if no answer exist then print "-1".
Constraints: 1 ≤ N ≤ 100 1 ≤ R ≤ 100
SAMPLE INPUT 4 2
SAMPLE OUTPUT 3
Explanation
Let the 2 groups be A and B respectively. Case 1: A gets 1 object and B gets 3 Case 2: A gets 2 objects and B gets 2 Case 3: A gets 3 objects and B gets 1
Assistant
MOD = 10000007 max_n = 100 # Precompute combination table using dynamic programming comb = [[0] * max_n for _ in range(max_n)] comb[0][0] = 1 for n in range(1, max_n): comb[n][0] = 1 for k in range(1, n): comb[n][k] = (comb[n-1][k-1] + comb[n-1][k]) % MOD comb[n][n] = 1 # Read input N, R = map(int, input().split()) if R > N: print(-1) else: n = N - 1 k = R - 1 print(comb[n][k] % MOD)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.