description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | from sys import stdin, stdout
input = stdin.readline
mp = lambda: map(int, input().split())
it = lambda: int(input())
n, k, d = mp()
mod = 10**9 + 7
dp = [0] * (n + 1)
dp1 = [0] * (n + 1)
dp[0] = 1
dp1[0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i >= j:
dp[i] += dp[i - j]
dp[i] %= mod
for r in range(1, d):
if i >= r:
dp1[i] += dp1[i - r]
dp1[i] %= mod
print((dp[n] - dp1[n]) % mod) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 10**9 + 7
I = lambda: list(map(int, input().split()))
[n, k, d] = list(map(int, input().split()))
def F(n, x):
f = [1] + [0] * n
for i in range(1, n + 1):
f[i] = sum(f[max(i - x, 0) : i])
return f[n]
print((F(n, k) - F(n, d - 1)) % MOD) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR RETURN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
s1 = [0] * 110
s2 = [0] * 110
s1[0], s2[0] = 1, 1
mod = 10**9 + 7
for i in range(1, n + 1):
for j in range(1, k + 1):
if j > i:
break
else:
s1[i] += s1[i - j]
for j in range(1, d):
if j > i:
break
else:
s2[i] += s2[i - j]
print((s1[n] - s2[n]) % mod) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def dp(curr, least, k, total, loc=0):
global d
if curr == total:
return int(least == 0)
if d[curr][int(least == 0)] != -1:
return d[curr][int(least == 0)]
for i in range(1, k + 1):
if curr + i > total:
break
loc += dp(curr + i, 0 if least <= i else least, k, total)
d[curr][int(least == 0)] = loc % 1000000007
return loc % 1000000007
n, k, dd = map(int, input().split())
d = [[-1, -1] for i in range(n)]
print(dp(0, dd, k, n)) | FUNC_DEF NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def read_input():
line = input().strip().split()
n = int(line[0])
k = int(line[1])
d = int(line[2])
print(calculate(n, k, d, {}) % (10**9 + 7))
def calculate(n, k, d, memo):
if (n, d) in memo:
return memo[n, d]
else:
if (n, d) == (0, 0):
return 1
x = 0
for i in range(1, min(k, n) + 1):
if i >= d:
x += calculate(n - i, k, 0, memo)
elif n >= i + d:
x += calculate(n - i, k, d, memo)
memo[n, d] = x
return x
read_input() | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR DICT BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR IF VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | N, K, D = [int(i) for i in input().split()]
M = 100
T = [[0] * (M + 1), [0] * (M + 1)]
for k in range(1, K + 1):
T[k >= D][k] = 1
for n in range(1, M + 1):
for k in range(1, K + 1):
if n + k > M:
continue
T[1][n + k] += T[1][n]
T[k >= D][n + k] += T[0][n]
print(T[1][N] % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
l = max(n, k)
m = min(n, k)
dp = [0] * (2 * l + 1)
dp[l] = 1
dp2 = dp.copy()
for i in range(l + 1, l + n + 1):
for j in range(1, m + 1):
dp[i] += dp[i - j]
for j in range(1, d):
dp2[i] += dp2[i - j]
print((dp[l + n] - dp2[l + n]) % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
N = 10**9 + 7
L = max(n, k) + 1
wd = [0] * L
pwd = [0] * L
nd = [1] * L
pnd = [1] * L
for i in range(1, d):
nd[i] = pnd[i - 1] % N
pnd[i] = (pnd[i - 1] + nd[i]) % N
for i in range(d, k + 1):
nd[i] = (pnd[i - 1] - pnd[i - d]) % N
pnd[i] = (pnd[i - 1] + nd[i]) % N
wd[i] = (pnd[i - d] + pwd[i - 1]) % N
pwd[i] = (pwd[i - 1] + wd[i]) % N
for i in range(k + 1, n + 1):
nd[i] = (pnd[i - 1] - pnd[i - d]) % N
pnd[i] = (pnd[i - 1] + nd[i]) % N
wd[i] = (pnd[i - d] - pnd[i - k - 1] + pwd[i - 1] - pwd[i - k - 1]) % N
pwd[i] = (pwd[i - 1] + wd[i]) % N
print(wd[n]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = list(map(int, input().split()))
dict1 = {}
for i in range(1, n + 1):
str1 = str(i) + "_" + "1" + "_" + "1"
dict1[str1] = i
for i in range(1, k + 1):
str1 = "1" + "_" + str(i) + "_" + "1"
dict1[str1] = 1
def solve(n, k, d, z):
str1 = str(n) + "_" + str(k) + "_" + str(d)
if n == 0 or n == d:
return 1
if d > k or n < 0 or d > n:
return 0
if str1 in dict1.keys():
return dict1[str1]
else:
ans = 0
for i in range(k, d - 1, -1):
ans += solve(n - i, k, 1, z)
ans %= z
for j in range(1, d):
ans += solve(n - j, k, d, z)
ans %= z
dict1[str1] = ans
return ans
z = 10**9 + 7
print(solve(n, k, d, z)) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING STRING STRING STRING ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING STRING FUNC_CALL VAR VAR STRING STRING ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR FUNC_CALL VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 10**9 + 7
def find(n, k, d):
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
j = i - 1
c = 0
s = 0
while j >= 0 and c < k:
s = (s + dp[j]) % mod
j -= 1
c += 1
dp[i] = s
return dp[-1]
n, k, d = map(int, input().split())
print((find(n, k, d) - find(n, d - 1, d)) % mod) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def dp(n, k, d, f, m):
if n == 0:
if f == True:
return 1
return 0
if n < 0:
return 0
if m[n][f] != -1:
return m[n][f]
res = 0
for i in range(1, k + 1):
if i >= d:
res += dp(n - i, k, d, f | True, m)
else:
res += dp(n - i, k, d, f | False, m)
m[n][f] = res % 1000000007
return m[n][f]
n, k, d = [int(x) for x in input().split()]
m = [[-1, -1] for _ in range(n + 1)]
print(dp(n, k, d, False, m)) | FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 1000000007
n, k, d = map(int, input().split())
arr = []
for i in range(n + 1):
t = [0, 0]
arr.append(t)
if n < d:
print(0)
else:
arr[1][0] = 1
arr[d][1] = 1
if d == 1:
arr[1][0] = 0
for i in range(2, n + 1):
temp = 0
if i < d:
temp += 1
for j in range(i - 1, max(0, i - d), -1):
temp += arr[j][0]
temp %= mod
arr[i][0] = temp
for i in range(d + 1, n + 1):
temp = 0
for j in range(i - 1, max(d - 1, i - k - 1), -1):
temp += arr[j][1]
temp %= mod
if i <= k:
temp += 1
temp %= mod
for j in range(i - d, max(0, i - k - 1), -1):
temp += arr[j][0]
temp %= mod
arr[i][1] = temp
print(arr[n][1] % mod) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = list(map(int, input().split()))
f = [0] * (n + k + 1)
f_ = [0] * (n + k + 1)
f_[0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
f[i] += f[i - j]
for j in range(d, k + 1):
f[i] += f_[i - j]
for j in range(1, d):
f_[i] += f_[i - j]
print(f[n] % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
mod = 1000000007
memo = [([-1] * 100) for i in range(n + 1)]
def dp(nn, s):
sum1 = 0
if nn == 0:
if s == 0:
return 0
else:
return 1
if memo[nn][s] != -1:
return memo[nn][s]
for i in range(1, min(k, nn) + 1):
sum1 = (sum1 % mod + dp(nn - i, 1 if s == 1 or i >= d else 0) % mod) % mod
memo[nn][s] = sum1
return sum1
r = dp(n, 0)
print(r) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
import time
def read_line(cast=None):
if cast is not None:
return cast(input().strip())
else:
return input().strip()
def read_list(cast=int):
return list(map(cast, read_line().split()))
INTMAX = 1000000007
res = 0
def dfs(n, k, d, t=False):
global res, INTMAX
if n < 0:
return
if n == 0 and not t:
return
if n == 0 and t:
res = (res + 1) % INTMAX
return
for i in range(1, k + 1):
dfs(n - i, k, d, t or i >= d)
def solve(n, k, d):
global res, INTMAX
res = 0
dp = [[(0) for _ in range(2)] for _ in range(101)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j < 0:
break
if j < d:
dp[i][0] = (dp[i][0] + dp[i - j][0]) % INTMAX
dp[i][1] = (dp[i][1] + dp[i - j][1]) % INTMAX
else:
dp[i][1] = (dp[i][1] + dp[i - j][0]) % INTMAX
dp[i][1] = (dp[i][1] + dp[i - j][1]) % INTMAX
print(dp[n][1])
n, k, d = read_list()
solve(n, k, d) | IMPORT IMPORT FUNC_DEF NONE IF VAR NONE RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF NUMBER IF VAR NUMBER RETURN IF VAR NUMBER VAR RETURN IF VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | from sys import stdin, stdout
input = stdin.readline
def print(x):
stdout.write(str(x) + "\n")
mod = 10**9 + 7
def solve():
l = list(map(int, input().split()))
n, k, d = l
dp = [([0] * 2) for i in range(n + 1)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
if j >= d:
dp[i][1] += (dp[i - j][0] + dp[i - j][1]) % mod
dp[i][1] %= mod
else:
dp[i][0] = (dp[i][0] + dp[i - j][0]) % mod
dp[i][1] = (dp[i][1] + dp[i - j][1]) % mod
print(dp[n][1])
t = 1
for _ in range(t):
solve() | ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp0 = [0] * (n + 1)
dp0[0] = 1
dp1 = [0] * (n + 1)
for i in range(1, n + 1):
j = 1
while k >= j:
if i - j < 0:
break
if j < d:
dp0[i] += dp0[i - j]
dp1[i] += dp1[i - j]
else:
dp1[i] += dp0[i - j]
dp1[i] += dp1[i - j]
j += 1
print(dp1[-1] % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split(" "))
a = [0] * (n + 1)
b = [0] * (n + 1)
a[0] = 1
b[0] = 1
m = 1000000007
for i in range(1, n + 1):
a[i] = 0
b[i] = 0
j = 1
while j <= k and i - j >= 0:
a[i] = a[i] + a[i - j]
j = j + 1
j = 1
while j < d and i - j >= 0:
b[i] = b[i] + b[i - j]
j = j + 1
print((a[n] % m - b[n] % m) % m) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
MOD = int(1000000000.0 + 7)
dp = [[([0] * (n + 1)) for i in range(n + 1)] for z in range(2)]
dp[0][0][0] = 1
res = 0
for i in range(1, n + 1):
for s in range(1, n + 1):
d0 = 0
d1 = 0
for v in range(1, min(d, s + 1)):
d0 += dp[0][i - 1][s - v]
d1 += dp[1][i - 1][s - v]
for v in range(d, min(k + 1, s + 1)):
d1 += dp[0][i - 1][s - v]
d1 += dp[1][i - 1][s - v]
dp[0][i][s] = d0 % MOD
dp[1][i][s] = d1 % MOD
res += dp[1][i][n]
print(res % MOD) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
sys.setrecursionlimit(1500)
def get_ints():
return list(map(int, sys.stdin.readline().strip().split()))
arr = get_ints()
n = arr[0]
k = arr[1]
d = arr[2]
dicts = {}
ans = 0
def dfs(v, flag):
strs = str(v) + "," + str(flag)
if strs in dicts:
return dicts[strs]
if v > n:
dicts[strs] = 0
return 0
if v == n and flag == 1:
dicts[strs] = 1
return 1
if v == n:
dicts[strs] = 0
return 0
temp = 0
for i in range(1, k + 1):
if i >= d:
flag = 1
temp += dfs(i + v, flag)
dicts[strs] = temp
return temp % 1000000007
for i in range(1, k + 1):
flag = 0
if i >= d:
flag = 1
if i == n and flag == 1:
ans += 1
break
if i == n and flag == 0:
break
if i > n:
break
dfs(i, flag)
strs = str(i) + "," + str(flag)
ans += dicts[strs]
ans = ans % 1000000007
print(ans % 1000000007) | IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
b = 10**9 + 7
ways = [0] * (n + 1)
ways.insert(0, 0)
j = 1
s = 0
while j <= min(k, n):
ways[j] = 1
j += 1
s += ways[n]
for i in range(2, n + 1):
new_ways = [0] * (n + 1)
for j in range(1, n + 1):
for p in range(1, k + 1):
if j + p <= n:
new_ways[j + p] += ways[j]
ways = []
for j in new_ways:
ways.append(j)
s += ways[n]
s = s % b
ways = [0] * (n + 1)
ways.insert(0, 0)
j = 1
r = 0
while j <= min(d - 1, n):
ways[j] = 1
j += 1
r += ways[n]
for i in range(2, n + 1):
new_ways = [0] * (n + 1)
for j in range(1, n + 1):
for p in range(1, d):
if j + p <= n:
new_ways[j + p] += ways[j]
ways = []
for j in new_ways:
ways.append(j)
r += ways[n]
r = r % b
print((s - r) % b) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
kp = [-1] * (n + 1)
def CP(m):
global k
if m == 0:
return 1
if kp[m] != -1:
return kp[m]
c = 0
for t in range(1, min(m, k) + 1):
c += CP(m - t)
c = c % 1000000007
kp[m] = c
return c
kc = [-1] * (n + 1)
def CP2(m):
global d
if m == 0:
return 1
if kc[m] != -1:
return kc[m]
c = 0
for t in range(1, min(m, d - 1) + 1):
c += CP2(m - t)
c = c % 1000000007
kc[m] = c
return c
print((CP(n) - CP2(n)) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | N, K, D = map(int, input().split())
mod = 10**9 + 7
dpK = [(0) for i in range(N + 1)]
dpK[0] = 1
for i in range(1, N + 1):
for j in range(1, K + 1):
if i >= j:
dpK[i] += dpK[i - j]
dpK[i] %= mod
dp = [(0) for i in range(N + 1)]
dp[0] = 1
for i in range(1, N + 1):
for j in range(1, D):
if i >= j:
dp[i] += dp[i - j]
dp[i] %= mod
ans = dpK[N] - dp[N]
print(ans % mod) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
mat = [1]
sat = [1]
for i in range(1, n + 1):
mat.append(sum(mat[max(i - d + 1, 0) :]))
sat.append(sum(sat[max(i - k, 0) :]))
print((sat[-1] - mat[-1]) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | s = input()
s1 = s.split()
tot = int(s1[0])
n = int(s1[1])
d = int(s1[2])
l = [int(i) for i in range(1, n + 1)]
final = 0
temp = tot
dp = [(0) for i in range(temp + 1)]
dp[0] = 1
for i in range(1, temp + 1):
sum1 = 0
for j in range(1, n + 1):
if i - j >= 0:
sum1 = sum1 + dp[i - j]
dp[i] = sum1
temp2 = dp[tot]
dp = [(0) for i in range(temp + 1)]
dp[0] = 1
for i in range(1, temp + 1):
sum1 = 0
for j in range(1, d):
if i - j >= 0:
sum1 = sum1 + dp[i - j]
dp[i] = sum1
temp3 = dp[tot]
print((temp2 - temp3) % 1000000007) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [[(0) for i in range(2)] for i in range(101)]
dp[0][0] = 1
dp[0][1] = 1
for i in range(1, 101):
dp[i][0] = sum(dp[j][0] for j in range(i - min(i, d), i))
if min(i, d) == d:
dp[i][0] = dp[i][0] - dp[i - d][0]
dp[i][1] = sum(dp[j][1] for j in range(i - min(i, k), i))
pri = 10**9 + 7
print((dp[n][1] - dp[n][0]) % pri) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [0] * (n + 1)
mod = 10**9 + 7
dp[0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i >= j:
dp[i] += dp[i - j]
dp[i] %= mod
if d == 1:
print(dp[n])
else:
dp1 = [0] * (n + 1)
dp1[0] = 1
for i in range(1, n + 1):
for j in range(1, d):
if i >= j:
dp1[i] += dp1[i - j]
dp1[i] %= mod
print((dp[n] - dp1[n]) % mod) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 10**9 + 7
def solve(n, k):
dp = [0] * 101
if k <= 0:
return 0
for i in range(1, k + 1):
dp[i] = 1
for i in range(1, n + 1):
for j in range(1, min(k + 1, i)):
dp[i] = dp[i] + dp[i - j]
dp[i] = dp[i] % mod
return dp[n]
mod = 10**9 + 7
a = list(map(int, input().split()))
q = solve(a[0], a[1]) - solve(a[0], a[2] - 1)
q = (mod + q) % mod
print(q) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | input_ = list(map(int, input().split()))
n, k, d = input_[0], input_[1], input_[2]
dp = [["None" for i in range(d + 1)] for j in range(n + 1)]
for j in range(d + 1):
dp[0][j] = 0
for i in range(n + 1):
if j > i:
dp[i][j] = 0
if dp[1][j] == "None":
dp[1][j] = 1
for i in range(min(d + 1, n + 1)):
if dp[i][i] == "None":
dp[i][i] = 1
for n_temp in range(1, n + 1):
for d_temp in range(d + 1):
if dp[n_temp][d_temp] == "None":
dp[n_temp][d_temp] = sum(
[
dp[n_temp - i][
((d_temp - i) * (i >= d_temp) + d_temp * (i < d_temp))
* ((d_temp - i) * (i >= d_temp) + d_temp * (i < d_temp) >= 0)
]
for i in range(1, min([k + 1, n_temp + 1]))
]
) + (n_temp <= k)
print(dp[n][d] % (10**9 + 7)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [[(0) for _ in range(2)] for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n + 1):
for j in range(i - 1, -1, -1):
if i - j > k:
break
if i - j < d:
dp[i][0] += dp[j][0]
dp[i][1] += dp[j][1]
if i - j >= d and i - j <= k:
dp[i][1] += dp[j][0] + dp[j][1]
print(dp[n][1] % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
f = sys.stdin
n, k, d = map(int, f.readline().strip().split())
Nd = [[1] * (n + 1), [1] * (n + 1)]
Nd[1][0] = 0
Nd[1][1] = 0
for i in range(2, n + 1):
N = 0
for j in range(1, k + 1):
if i >= j:
N += Nd[0][i - j]
Nd[0][i] = N
N = 0
for j in range(1, k + 1):
if i >= j:
if j >= d:
N += Nd[0][i - j]
else:
N += Nd[1][i - j]
Nd[1][i] = N
if d > 1:
print(Nd[1][n] % 1000000007)
else:
print(Nd[0][n] % 1000000007) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
mod = 10**9 + 7
add = [0] * 105
sub = [0] * 105
add[0] = sub[0] = 1
for i in range(n + 1):
for p in range(min(n - i, k)):
add[p + i + 1] = (add[p + i + 1] + add[i]) % mod
for q in range(min(n - i, d - 1)):
sub[q + i + 1] = (sub[q + i + 1] + sub[i]) % mod
print((add[n] - sub[n] + mod) % mod) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 10**9 + 7
n, k, d = [int(x) for x in input().split()]
include = [(0) for i in range(n + 1)]
exclude = [(0) for i in range(n + 1)]
for i in range(n + 1):
if i <= k:
include[i] = 1
if i < d:
exclude[i] = 1
include[0] = exclude[0] = 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
continue
include[i] += include[i - j] % MOD
if j < d:
exclude[i] += exclude[i - j] % MOD
print((include[n] - exclude[n]) % MOD) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MODULO = int(1000000000.0) + 7
def findnumways(n, d_state, k, d, num_ways):
if n < 0:
return 0
if n == 0 and not d_state:
return 0
if n == 0 and d_state:
return 1
if (n, d_state) in num_ways:
return num_ways[n, d_state]
cnt = 0
for i in range(1, k + 1):
if i < d:
cnt += findnumways(n - i, False or d_state, k, d, num_ways) % MODULO
else:
cnt += findnumways(n - i, True, k, d, num_ways) % MODULO
num_ways[n, d_state] = cnt % MODULO
return cnt % MODULO
n, k, d = map(int, input().split())
num_ways = dict()
print(findnumways(n, False, k, d, num_ways) % MODULO) | ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 1000000007
dp = [[(-1) for i in range(2)] for j in range(101)]
def k_tree(n, k, d, least_d_selected):
if least_d_selected:
selected_index = 1
else:
selected_index = 0
if n < 0:
return 0
if n == 0 and least_d_selected:
return 1
if n == 0 and not least_d_selected:
return 0
temp = 0
if dp[n][selected_index] != -1:
return dp[n][selected_index]
for i in range(k):
if not least_d_selected and i + 1 >= d:
temp += k_tree(n - (i + 1), k, d, True)
temp %= MOD
else:
temp += k_tree(n - (i + 1), k, d, least_d_selected)
temp %= MOD
dp[n][selected_index] = temp
return dp[n][selected_index]
def k_tree_runner():
line = input()
sn, sk, sd = line.split(" ")
n = int(sn)
k = int(sk)
d = int(sd)
print(k_tree(n, k, d, False))
k_tree_runner() | ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = [int(x) for x in input().split()]
dp = [(1) for i in range(n + 1)]
for i in range(1, n + 1):
dp[i] = sum([dp[i - j] for j in range(1, k + 1) if i - j >= 0])
dp_d1 = [(1) for i in range(n + 1)]
for i in range(1, n + 1):
dp_d1[i] = sum([dp_d1[i - j] for j in range(1, min(k + 1, d)) if i - j >= 0])
print((dp[n] - dp_d1[n]) % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [[(0) for j in range(2)] for i in range(105)]
dp[0][1] = 1
for i in range(1, n + 1):
for j in range(1, min(i, k) + 1):
dp[i][0] = (dp[i][0] + dp[i - j][j >= d]) % 1000000007
dp[i][1] = (dp[i][1] + dp[i - j][1]) % 1000000007
print(dp[n][0]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 1000000007
n, k, d = map(int, input().split())
if n < d:
print(0)
else:
dp = [0] * (n + 1)
dp[0] = 1
dpp = [0] * (n + 1)
dpp[0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i >= j:
dp[i] = (dp[i - j] + dp[i]) % mod
if i >= j and j < d:
dpp[i] = (dpp[i - j] + dpp[i]) % mod
print((dp[n] - dpp[n]) % mod) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | dp = [0] * 101
dpx = [0] * 101
n, k, d = input().split()
n = int(n)
k = int(k)
d = int(d)
dp[0] = 1
dpx[0] = 1
for i in range(1, n + 1):
for j in range(1, min(i, k) + 1):
dp[i] = dp[i] + dp[i - j]
for i in range(1, n + 1):
for j in range(1, min(i, d - 1) + 1):
dpx[i] = dpx[i] + dpx[i - j]
print((dp[n] - dpx[n]) % 1000000007) | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | dp = []
def f(n, k, d):
global dp
if n < 0:
return 0
if n == 0 and d == 0:
dp[n][k][d] = 1
return 1
if dp[n][k][d] != -1:
return dp[n][k][d]
cont = 0
for i in range(1, k + 1):
cont += f(n - i, k, 0 if i >= d else d)
dp[n][k][d] = cont
return cont
def main():
global dp
n, k, d = [int(i) for i in input().split()]
dp = [[[(-1) for j2 in range(d + 1)] for j in range(k + 1)] for i in range(n + 1)]
print(f(n, k, d) % 1000000007)
return
main() | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = {}
vis = []
def F(curr, poss):
if curr < 0:
return 0
if curr == 0 and poss == 1:
return 1
if (curr, poss) in vis:
return dp[curr, poss]
i = 1
vis.append((curr, poss))
dp[curr, poss] = 0
while i < d:
dp[curr, poss] += F(curr - i, poss)
i += 1
i = d
while i <= k:
dp[curr, poss] += F(curr - i, 1)
i += 1
return dp[curr, poss] % 1000000007
print(F(n, 0)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
sys.setrecursionlimit(100000)
n, k, d = [int(x) for x in sys.stdin.readline().strip().split()]
memo = {}
m = 10**9 + 7
def dp(n, k, d):
key = str(n) + str(d)
if n == 0:
return 1
if n < 0:
return 0
if key in memo:
return memo[key]
s = 0
for i in range(1, k + 1):
if i >= d:
s += dp(n - i, k, 0)
elif n - i >= d:
s += dp(n - i, k, d)
memo[key] = s
return s
print(dp(n, k, d) % m) | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def sol(n, k, d):
if n <= d:
if n == d:
return 1
else:
return 0
if (n, k, d) not in dic:
ans = 0
for i in range(1, k + 1):
if i >= d:
ans += sol(n - i, k, 0)
else:
ans += sol(n - i, k, d)
dic[n, k, d] = ans % 1000000007
return dic[n, k, d]
A = list(map(int, input().split()))
dic = {}
print(sol(A[0], A[1], A[2])) | FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [[-1, -1] for j in range(101)]
m = 10**9 + 7
def ans(n, t):
global d, m, k
if dp[n][t] >= 0:
return dp[n][t]
if n == d and t == 0:
return 1
if n < d and t == 0:
return 0
if n == 0:
return 1
c = 0
for i in range(1, d):
if n >= i:
c += ans(n - i, t)
c %= m
for i in range(d, k + 1):
if n >= i:
c += ans(n - i, 1)
c %= m
dp[n][t] = c % m
return c % m
print(ans(n, 0)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def main():
mod = 10**9 + 7
n, k, d = map(int, input().split())
dp = [0] * (n + 1)
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j >= 0:
dp[i] += dp[i - j]
dp[i] %= mod
if i <= k:
dp[i] += 1
dp1 = [0] * (n + 1)
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j >= 0 and j < d:
dp1[i] += dp1[i - j]
dp1[i] %= mod
if i <= k and i < d:
dp1[i] += 1
ans = dp[n] - dp1[n]
print(ans % mod)
main() | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def prog():
n, k, d = map(int, input().split())
mod = 10**9 + 7
ways = [(0) for i in range(n + 1)]
for i in range(1, min(k + 1, n + 1)):
ways[i] = 1
for i in range(1, n + 1):
for j in range(max(1, i - k), i):
ways[i] += ways[j]
ways_less_d = [(0) for i in range(n + 1)]
k = d - 1
for i in range(1, min(k + 1, n + 1)):
ways_less_d[i] = 1
for i in range(1, n + 1):
for j in range(max(1, i - k), i):
ways_less_d[i] += ways_less_d[j]
print((ways[n] - ways_less_d[n]) % mod)
prog() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
M = 10**9 + 7
dp = [[(0) for i in range(2)] for j in range(n + 1)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j >= 0:
dp[i][1] = (dp[i][1] + dp[i - j][1]) % M
if j >= d:
dp[i][1] = (dp[i][1] + dp[i - j][0]) % M
else:
dp[i][0] = (dp[i][0] + dp[i - j][0]) % M
print(dp[n][1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
mod = 10**9 + 7
dp = [([0] * (k + 1)) for i in range(n + 1)]
dp[0][0] = 1
for su in range(n + 1):
for mi in range(k + 1):
for i in range(1, k + 1):
if su + i <= n:
dp[su + i][max(i, mi)] += dp[su][mi] % mod
print(int(sum(dp[n][d:]) % mod)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 10**9 + 7
n, k, d = [int(k) for k in input().split()]
ways1 = [0] * (n + 1)
ways1[0] = 1
ways1[1] = 1
for i in range(2, n + 1):
for j in range(max(0, i - k), i):
ways1[i] += ways1[j]
ways1[i] %= MOD
ways2 = [0] * (n + 1)
ways2[0] = 1
ways2[1] = 1
if d == 1:
ways2[0] = 0
ways2[1] = 0
for i in range(2, n + 1):
for j in range(max(0, i - (d - 1)), i):
ways2[i] += ways2[j]
ways2[i] %= MOD
print((ways1[n] - ways2[n]) % MOD) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
a = [1]
b = [0]
for i in range(1, n + 1):
a.append(sum(a[max(i - d + 1, 0) :]))
b.append(sum(a[max(i - k, 0) : max(i - d + 1, 0)]) + sum(b[max(i - k, 0) :]))
print(b[n] % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = input().split()
n = int(n)
k = int(k)
d = int(d)
dp = [0] * (n + 1)
s = [0] * (n + 1)
dp[0] = 1
s[0] = 1
if n < d:
print(0)
else:
for i in range(1, n + 1):
for j in range(1, k + 1):
if j <= i:
dp[i] = dp[i] + dp[i - j]
for j in range(1, d):
if j <= i:
s[i] = s[i] + s[i - j]
sum1 = 0
for i in range(n - d + 1, n):
sum1 += s[i]
print((dp[n] - sum1) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | inp = input().split()
n = int(inp[0])
k = int(inp[1])
d = int(inp[2])
dp = []
for i in range(0, 110):
dp.append(0)
dp[0] = 1
for i in range(0, n):
for j in range(1, k + 1):
if i + j > n:
break
else:
dp[i + j] = dp[i + j] + dp[i]
dp2 = []
for i in range(0, 110):
dp2.append(0)
dp2[0] = 1
for i in range(0, n):
for j in range(1, d):
if i + j > n:
break
else:
dp2[i + j] = dp2[i + j] + dp2[i]
print((dp[n] - dp2[n]) % 1000000007) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | from sys import stderr, stdin
def readInts():
return map(int, stdin.readline().strip().split())
def print_err(*args, **kwargs):
print(*args, file=stderr, **kwargs)
def naive_kt(k, d, n):
if n < 0:
return 0
if n < d:
return 0
if n == 0:
return 1
s = 0
for i in range(1, k + 1):
d2 = 0
if i >= d:
d2 = 0
else:
d2 = d
s += naive_kt(k, d2, n - i)
return s
def dp_kt(k, d, n):
a_d_used = [1]
a_d_unused = [0]
for ni in range(1, n + 1):
s = 0
for si in range(max(0, ni - k), ni):
s += a_d_used[si]
a_d_used.append(s)
for ni in range(1, n + 1):
s = 0
for si in range(1, k + 1):
if ni - si < 0:
continue
v = a_d_unused[ni - si]
if si >= d:
v = a_d_used[ni - si]
s += v
a_d_unused.append(s)
return a_d_used, a_d_unused
def solve(vs):
return None
def run():
modval = 10**9 + 7
n, k, d = readInts()
_, dp = dp_kt(k, d, n)
print(dp[-1] % modval)
run() | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF RETURN NONE FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [None, (0, 1)] if d > 1 else [None, (1, 1)]
for i in range(2, n + 1):
if i < d:
s, u = 0, 1
elif i <= k:
s = u = 1
else:
s = u = 0
for j in range(1, min(i, k + 1)):
if j < d:
s += dp[i - j][0]
else:
s += dp[i - j][1]
u += dp[i - j][1]
dp.append((s % 1000000007, u % 1000000007))
print(dp[-1][0]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER LIST NONE NUMBER NUMBER LIST NONE NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
input = sys.stdin.readline
def inInt():
return int(input())
def inStr():
return input().strip("\n")
def inIList():
return list(map(int, input().split()))
def inSList():
return input().split()
def bsearch(nums, target):
N = len(nums or [])
l = 0
r = N - 1
while l <= r:
mid = (l + r) // 2
if nums[mid] < target:
l = mid + 1
elif nums[mid] > target:
r = mid - 1
else:
return None, mid, None
return r if r >= 0 else None, None, l if l <= N - 1 else None
def yesOrNo(val):
print("YES" if val else "NO")
def printSpacedArray(nums):
print(*nums)
n, k, d = inIList()
dp = [[(0) for i in range(2)] for i in range(101)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(1, n + 1):
dp[i][0] = 0
dp[i][1] = 0
for j in range(1, k + 1):
if j > i:
break
if j < d:
dp[i][0] += dp[i - j][0]
dp[i][1] += dp[i - j][1]
dp[i][0] %= 1000000007
dp[i][1] %= 1000000007
else:
dp[i][1] += dp[i - j][0]
dp[i][1] += dp[i - j][1]
dp[i][1] %= 1000000007
print(dp[n][1]) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN NONE VAR NONE RETURN VAR NUMBER VAR NONE NONE VAR BIN_OP VAR NUMBER VAR NONE FUNC_DEF EXPR FUNC_CALL VAR VAR STRING STRING FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 10**9 + 7
path = [([-1] * 2) for _ in range(101)]
def count(i, state):
if path[i][state] != -1:
return path[i][state]
if i == 0:
return state
result = 0
for j in range(1, k + 1):
if i >= j:
result = (result + count(i - j, [1, state][j < d])) % mod
path[i][state] = result
return path[i][state]
n, k, d = map(int, input().split())
print(count(n, 0)) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR LIST NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
l = [1] + [0] * n
m = [1] + [0] * n
for i in range(0, n + 1):
for j in range(1, d):
if i + j <= n:
l[i + j] += l[i]
for i in range(0, n + 1):
for j in range(1, k + 1):
if i + j <= n:
m[i + j] += m[i]
print((m[n] - l[n]) % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = int(1000000000.0 + 7)
n, k, d = map(int, input().split())
dp = [(0) for i in range(n + k + 1)]
dp[0] = 1
for i in range(n + 1):
for j in range(1, k + 1):
dp[i + j] += dp[i]
dp2 = [(0) for i in range(n + k + 1)]
dp2[0] = 1
for i in range(n + 1):
for j in range(1, d):
dp2[i + j] += dp2[i]
print((dp[n] - dp2[n]) % mod) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | inp = input().split()
n = int(inp[0])
k = int(inp[1])
d = int(inp[2])
if n < d:
print(0)
else:
D = [[(0) for i in range(n + 1)], [(0) for j in range(n + 1)]]
D[0][0] = 0
D[1][0] = 0
for j in range(n):
if j + 1 <= k and d <= j + 1:
D[1][j + 1] = 1
elif j + 1 <= k and d > j + 1:
D[0][j + 1] = 1
for i in range(d - 1):
if j - i - 1 >= 0:
D[1][j + 1] += D[1][j - i]
D[0][j + 1] += D[0][j - i]
else:
break
for i in range(k - d + 1):
if j + 1 - d - i >= 0:
D[1][j + 1] += D[1][j + 1 - i - d] + D[0][j + 1 - i - d]
else:
break
print(D[1][n] % 1000000007) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [[(0) for j in range(2)] for i in range(101)]
dp[0][1] = 1
for i in range(1, n + 1):
for j in range(1, min(i, k) + 1):
if j >= d:
dp[i][0] = (dp[i][0] + dp[i - j][1]) % int(1000000000.0 + 7)
else:
dp[i][0] = (dp[i][0] + dp[i - j][0]) % int(1000000000.0 + 7)
dp[i][1] = (dp[i][1] + dp[i - j][1]) % int(1000000000.0 + 7)
print(dp[n][0]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def calculateWays(summ, maxNumber):
p = [0] * (summ + 1)
dp = []
for i in range(summ + 1):
dp.append(p.copy())
for i in range(summ):
for j in range(summ):
x = i + 1
y = j + 1
if x <= y:
prevWays = 0
for ii in range(y - 1):
if ii < maxNumber:
prevWays = (prevWays + dp[x - 1][y - ii - 1]) % 1000000007
if y <= maxNumber and x == 1:
dp[x][y] = (prevWays + 1) % 1000000007
else:
dp[x][y] = prevWays % 1000000007
ans = 0
for i in range(summ):
ans = ans + dp[i + 1][summ]
return ans
def main():
n, k, d = list(map(int, input().split()))
print((calculateWays(n, k) - calculateWays(n, d - 1)) % 1000000007)
main() | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 10**9 + 7
n, k, d = map(int, input().strip().split())
notD = [(0) for i in range(n + 1)]
notD[0] = 1
withD = [(0) for i in range(n + 1)]
withD[0] = 1
for i in range(n + 1):
for j in range(1, d):
if i >= j:
notD[i] += notD[i - j]
for i in range(n + 1):
for j in range(1, k + 1):
if i >= j:
withD[i] += withD[i - j]
print((withD[n] - notD[n]) % mod) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(" "))
def solve():
n, k, d = read_tuple(int)
edges = [i for i in range(1, k + 1)]
cnt_normal = [(0) for _ in range(n + 1)]
cnt_d = [(0) for _ in range(n + 1)]
for i in range(1, n + 1):
for edge in edges:
if i == edge:
cnt_normal[i] += 1
if edge < d:
cnt_d[i] += 1
if i - edge >= 0:
cnt_normal[i] += cnt_normal[i - edge]
if edge < d:
cnt_d[i] += cnt_d[i - edge]
print((cnt_normal[n] - cnt_d[n]) % 1000000007)
solve() | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 10**9 + 7
def ktree(l, a, dp, k, d):
if l < 0:
return 0
if l == 0 and a == 0:
return 0
if l == 0 and a == 1:
return 1
if dp[l][a] != -1:
return dp[l][a]
sum = 0
for i in range(1, k + 1):
if i >= d:
sum += ktree(l - i, 1, dp, k, d)
else:
sum += ktree(l - i, a, dp, k, d)
dp[l][a] = sum
return dp[l][a]
s = str(input())
l = s.split()
n = int(l[0])
k = int(l[1])
d = int(l[2])
dp = [[(-1) for i in range(2)] for i in range(101)]
print(ktree(n, 0, dp, k, d) % mod) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
mod = 1000000007
get_arr = lambda: list(map(int, input().split()))
get_int = lambda: int(input())
get_ints = lambda: map(int, input().split())
get_str = lambda: input()
get_strs = lambda: input().split()
def fn(n, k, d, flag, cache, mod):
if n == 0 and flag:
return 1
if n == 0 and not flag:
return 0
if n < 0:
return 0
key = n, flag
if key in cache:
return cache[key]
ans = 0
for i in range(1, k + 1):
if i >= d:
ans += fn(n - i, k, d, True, cache, mod)
else:
ans += fn(n - i, k, d, flag, cache, mod)
if ans >= mod:
ans %= mod
cache[key] = ans
return ans
n, k, d = get_ints()
print(fn(n, k, d, False, {}, mod)) | IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER DICT VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
M = 10**9 + 7
def solve():
N, K, D = getInts()
dp = [[(0) for j in range(2)] for i in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
for j in range(1, min(K + 1, N + 1)):
if j < D:
dp[i][0] += dp[i - j][0]
dp[i][1] += dp[i - j][1]
else:
dp[i][1] += dp[i - j][0]
dp[i][1] += dp[i - j][1]
dp[i][0] %= M
dp[i][1] %= M
return dp[N][1]
ans = solve()
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR RETURN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def w(N, K):
a = [0] * (N + 1)
a[0] = 1
for i in range(1, min(N, K) + 1):
a[i] = sum(a[0:i])
if N > K:
for x in range(K + 1, N + 1):
a[x] = sum(a[x - K : x])
return a[-1]
def sol():
n, k, g = map(int, input().split(" "))
result = (w(n, k) - w(n, g - 1)) % (10**9 + 7)
print(result)
sol() | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def sums(n, k, d, dic):
count = 0
limited_count = 0
for i in range(1, k + 1):
if n - i == 0:
count += 1
if n >= d:
limited_count += 1
elif n - i < 0:
pass
else:
count += dic[n - i][0]
if i >= d:
limited_count += dic[n - i][0]
else:
limited_count += dic[n - i][1]
return count % (10**9 + 7), limited_count % (10**9 + 7)
def tree(n, k, d):
dic = {}
for i in range(1, n + 1):
dic[i] = sums(i, k, d, dic)
return dic[n][1]
lst = list(map(lambda elem: int(elem), input().split(" ")))
print(tree(lst[0], lst[1], lst[2])) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def f(k, n, d, b, l):
if n < 0 or b == 0 and n < d:
return 0
elif l[n][b] > 0:
return l[n][b]
else:
cnt = 0
for i in range(1, k + 1):
if i < d:
cnt += f(k, n - i, d, b, l)
else:
cnt += f(k, n - i, d, 1, l)
l[n][b] = cnt
return cnt
n, k, d = map(int, input().split())
l = [[0, 0] for i in range(n + 1)]
l[0] = [1, 1]
print(f(k, n, d, 0, l) % 1000000007) | FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = [int(x) for x in input().split()]
klist = [(0) for i in range(101)]
dminusonelist = [(0) for i in range(101)]
twopower = 1
for i in range(1, k + 1):
klist[i] = twopower
twopower = twopower * 2 % 1000000007
twopower = 1
for i in range(1, d):
dminusonelist[i] = twopower
twopower = twopower * 2 % 1000000007
for i in range(k + 1, 101):
thesum = 0
for j in range(i - k, i):
thesum = (thesum + klist[j]) % 1000000007
klist[i] = thesum
for i in range(d, 101):
thesum = 0
for j in range(i - d + 1, i):
thesum = (thesum + dminusonelist[j]) % 1000000007
dminusonelist[i] = thesum
if d == 1:
print(klist[n])
else:
tempanswer = klist[n] - dminusonelist[n]
if tempanswer < 0:
tempanswer += 1000000007
print(tempanswer) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | m = 1000000007
def mod_add(a, b):
return (a % m + b % m) % m
def solve(n, k, d, flag, dp):
if n < 0:
return 0
if n == 0:
if flag == False:
return 1
else:
return 0
if (n, flag) in dp:
return dp[n, flag]
temp = 0
f = flag
for i in range(1, k + 1):
if i >= d:
flag = False
temp = mod_add(temp, solve(n - i, k, d, flag, dp))
dp[n, f] = temp
return temp
arr = [int(x) for x in input().split()]
print(solve(arr[0], arr[1], arr[2], True, {})) | ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER DICT |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def F(n, k):
if k < 2:
return k
b = [0] * (k - 1) + [1]
for i in range(n):
b.append(sum(b[-k:]) % (10**9 + 7))
return b[-1]
n, k, d = list(map(int, input().split()))
ans = F(n, k) - F(n, d - 1)
if ans < 0:
ans += 10**9 + 7
print(ans) | FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def main():
n, k, d = map(int, input().split())
n += 1
k += 1
l1le, l1ge = [0] * n, [0] * n
l1le[0] = 1
res = 0
for _ in range(n - d + 1):
l0le, l0ge, l1le, l1ge = l1le, l1ge, [0] * n, [0] * n
for i, x in enumerate(l0le):
if x:
x %= 1000000007
for j in range(i + 1, i + d):
if j < n:
l1le[j] += x
for j in range(i + d, i + k):
if j < n:
l1ge[j] += x
for i, x in enumerate(l0ge):
if x:
x %= 1000000007
for j in range(i + 1, i + k):
if j < n:
l1ge[j] += x
res += l1ge[-1]
print(res % 1000000007)
main() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 10**9 + 7
def calculate(n, max_k):
if max_k == 0:
return 0
dp = [0] * (n + 1)
dp[1] = 1
for i in range(2, n + 1):
m = min(i - 1, max_k)
if i <= max_k:
dp[i] += 1
for j in range(1, m + 1):
dp[i] += dp[i - j]
dp[i] = dp[i] % MOD
return dp[-1]
n, k, d = list(map(int, input().split()))
if d > n:
print(0)
elif d == n:
print(1)
else:
total = calculate(n, k)
no_d = calculate(n, d - 1)
total -= no_d
if total < 0:
total += MOD
print(total) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR RETURN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = input().strip().split()
n = int(n)
k = int(k)
d = int(d)
dp = [(0) for i in range(102)]
dp[0] = 1
p = [(0) for i in range(102)]
p[0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j < 0:
break
dp[i] = (dp[i] + dp[i - j]) % 1000000007
for j in range(1, d):
if i - j < 0:
break
p[i] = (p[i] + p[i - j]) % 1000000007
print(((dp[n] - p[n]) % 1000000007 + 1000000007) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = list(map(int, input().split()))
def paths_with_weight(n, k, d):
if n == 0:
return 1 if d == 0 else 0
if n < 0:
return 0
return sum(
[paths_with_weight(n - i, k, d if i < d else 0) for i in range(1, k + 1)]
)
def dp_paths_with_weight(n, k, d, modulo=0):
P = [[(0) for b in range(2)] for i in range(n + 1)]
P[0][0] = 1
if modulo:
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j >= 0:
P[i][0] += P[i - j][0] % modulo
P[i][1] += (P[i - j][1] if j < d else P[i - j][0]) % modulo
return P[n][1] % modulo
else:
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j >= 0:
P[i][0] += P[i - j][0]
P[i][1] += P[i - j][1] if j < d else P[i - j][0]
return P[n][1]
print(dp_paths_with_weight(n, k, d, 1000000007)) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR RETURN BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | b = [False] * 101
x = [0] * 101
def count(w, k1):
if w == 0:
return 1
elif w < 0:
return 0
ans = 0
for i in range(1, k1 + 1):
if w - i < 0:
break
if b[w - i]:
ans = ans + x[w - i]
else:
x[w - i] = count(w - i, k1)
ans = ans + x[w - i]
b[w - i] = True
b[w] = True
x[w] = ans
return ans
n, k, d = map(int, input().split())
x[0] = 1
ans = count(n, k)
b = [False] * 101
x = [0] * 101
x[0] = 1
ans = ans - count(n, min(k, d - 1))
print(ans % 1000000007) | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp1 = [0] * (n + 1)
dp2 = [0] * (n + 1)
dp1[0] = 1
for i in range(1, n + 1):
for j in range(1, min(n, k) + 1):
dp2[i] += dp2[i - j]
if j < d:
dp1[i] += dp1[i - j]
else:
dp2[i] += dp1[i - j]
print(dp2[n] % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | dp1 = [0] * 101
dp2 = [0] * 101
n, k, d = map(int, input().split())
for i in range(1, k + 1):
dp1[i] = 1
if i < d:
dp2[i] = 1
dp1[0] = 0
dp2[0] = 0
m = 10**9 + 7
for i in range(1, n + 1):
for j in range(1, k + 1):
if i > j:
dp1[i] = (dp1[i] + dp1[i - j]) % m
if j < d:
dp2[i] = (dp2[i] + dp2[i - j]) % m
print((dp1[n] - dp2[n]) % m) | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def count(n, item):
new, x, summa, i = [], 1, 0, 0
for i in range(1, min(n + 1, item + 1)):
new.append(x)
summa += x
x *= 2
x = x % 1000000007
summa = summa % 1000000007
z = 0
for j in range(i + 1, n + 1):
new.append(summa)
summa += new[-1] - new[z]
summa = summa % 1000000007
z += 1
return new[-1]
n, k, d = map(int, input().split())
res = count(n, k) - count(n, d - 1)
if res < 0:
res += 1000000007
print(res) | FUNC_DEF ASSIGN VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | temp = list(map(int, input().split()))
n, k, d = temp[0], temp[1], temp[2]
mod = 1000000007
dp = [[0, 0] for _ in range(n + 1)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(1, n + 1):
for j in range(1, min(i, k) + 1):
if j < d:
dp[i][0] += dp[i - j][0] % mod
dp[i][1] += dp[i - j][1] % mod
else:
dp[i][1] += dp[i - j][0] % mod
dp[i][1] += dp[i - j][1] % mod
print(dp[n][1] % mod) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | from sys import stdin, stdout
n, k, d = stdin.readline().split()
n = int(n)
k = int(k)
d = int(d)
mod = 1000000007
wd = [(0) for i in range(n + 1)]
wo = [(0) for i in range(n + 1)]
wd[0] = 1
wo[0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j >= 0:
wd[i] += wd[i - j]
wd[i] %= mod
for i in range(1, n + 1):
for j in range(1, d):
if i - j >= 0:
wo[i] += wo[i - j]
wo[i] %= mod
ans = (wd[n] - wo[n]) % mod
stdout.write(str(ans)) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | dpall = []
dpd = []
MOD = 1000000007
n, k, d = map(int, input("").split(" "))
for i in range(105):
dpall.append(None)
dpd.append(None)
def solveD(u):
if u == 0:
return 1
if dpd[u] != None:
return dpd[u]
ans = 0
for i in range(1, min(min(d - 1, k), u) + 1):
ans += solveD(u - i)
dpd[u] = ans
return ans
def solveAll(u):
if u == 0:
return 1
if dpall[u] != None:
return dpall[u]
ans = 0
for i in range(1, min(k, u) + 1):
ans = ans + solveAll(u - i)
dpall[u] = ans
return ans
res = solveAll(n) - solveD(n)
print(res % MOD) | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NONE EXPR FUNC_CALL VAR NONE FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NONE RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NONE RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def run():
n, k, d = (int(x) for x in input().split(" "))
value = recurse(n, k, d, 0, dict()) % 1000000007
print(value)
def recurse(n, k, d, r, memo):
if n == 0:
if d == -1:
return 1
else:
return 0
elif n < 0:
return 0
key = "level={}, n={}, d={}".format(r, n, d)
if key in memo.keys():
return memo[key]
total = 0
for p in range(1, min(n + 1, k + 1)):
if p >= d:
d = -1
value = recurse(n - p, k, d, r + 1, memo)
total += value
memo[key] = total
return total
run() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL STRING VAR VAR VAR IF VAR FUNC_CALL VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mem = [[-1, -1] for x in range(0, 103)]
n, k, d = list(map(int, input().split()))
def dp(remain, has_d):
if remain == 0:
return has_d
if remain < 0:
return 0
if mem[remain][has_d] != -1:
return mem[remain][has_d]
mem[remain][has_d] = 0
for i in range(1, min(remain, k) + 1):
if i >= d:
mem[remain][has_d] += dp(remain - i, 1)
else:
mem[remain][has_d] += dp(remain - i, has_d)
return mem[remain][has_d]
print(dp(n, 0) % (10**9 + 7)) | ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | from sys import stdin
mod = 1000000007
def sol(n, k):
arr = [(0) for i in range(n + 1)]
acum = [(0) for i in range(n + 1)]
for i in range(1, min(k, n) + 1):
arr[i] = 1
acum[i] = 1
for qq in range(n):
arr1 = [(0) for i in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, k + 1):
if arr[i] != 0 and i + j < len(arr1):
arr1[i + j] = (arr1[i + j] + arr[i]) % mod
for i in range(n + 1):
acum[i] = (acum[i] + arr1[i]) % mod
arr = arr1.copy()
return acum[-1]
n, k, d = map(int, stdin.readline().strip().split())
print((sol(n, k) - sol(n, d - 1)) % mod) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR RETURN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def numWays(n, k):
if k == 0:
return 0
s = [1] * (n + 1)
for i in range(2, min(k + 1, n + 1)):
s[i] = s[i - 1] << 1
for i in range(k + 1, n + 1):
s[i] = (s[i - 1] << 1) - s[i - k - 1]
return s[n]
def solve():
n, k, d = map(int, input().split())
mod = 1000000007
print((numWays(n, k) - numWays(n, d - 1)) % mod)
solve() | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [[(0) for i in range(2)] for j in range(n + 10)]
dp[0][0] = 1
MOD = int(1000000000.0) + 7
for i in range(1, n + 1):
for j in range(1, min(d - 1, n) + 1):
dp[i][0] += dp[i - j][0] % MOD
for j in range(1, min(d - 1, n) + 1):
dp[i][1] += dp[i - j][1] % MOD
for j in range(d, min(n, k) + 1):
dp[i][1] += (dp[i - j][0] + dp[i - j][1]) % MOD
print(dp[n][1] % MOD) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = list(map(int, input().split()))
MOD = 10**9 + 7
dp = {}
def rec(remaining, flag=False):
if remaining < 0:
return 0
if remaining == 0 and flag == True:
return 1
if (remaining, flag) in dp:
return dp[remaining, flag]
ans = 0
for i in range(1, k + 1):
if i <= remaining:
ans += rec(remaining - i, flag | (i >= d))
ans %= MOD
dp[remaining, flag] = ans
return ans
ans = rec(n) % MOD
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT FUNC_DEF NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def k_tree(n, k, d):
def _k_tree(n, k):
if k <= 0 or n <= 0:
return 0
cache = [1] * n
for i in range(1, n):
sum_num = 0
for j in range(max(0, i - k), i):
sum_num += cache[j]
if i < k:
sum_num += 1
cache[i] = sum_num
return cache[-1]
return _k_tree(n, k) - _k_tree(n, d - 1)
n, k, d = map(int, input().strip().split())
print(k_tree(n, k, d) % 1000000007) | FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = input().split()
n, k, d = int(n), int(k), int(d)
mod = 10**9 + 7
dp = [1]
for i in range(1, n + 1):
if i == 1:
dp.append(1)
else:
dp.append(0)
for j in range(1, min(k, i) + 1):
dp[-1] += dp[i - j]
dp[-1] %= mod
DP = [0]
for i in range(1, n + 1):
if i < d:
DP.append(0)
else:
DP.append(0)
for j in range(1, min(k, i) + 1):
if j < d:
DP[-1] += DP[i - j]
else:
DP[-1] += dp[i - j]
DP[-1] %= mod
print(DP[-1]) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def solve(s):
n, k, d = list(map(int, s.split()))
return int((dp(n, k) - dp(n, d - 1)) % 1000000007)
def dp(n, k):
l = [(2**i) for i in range(k)]
while len(l) < n:
l.append(sum(l[-k:]))
return l[n - 1]
s = input()
print(solve(s)) | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | memo = {}
tg, k, d = map(int, input().split())
def rec(n):
if n in memo:
return memo[n]
ans = [0, 0]
for b in range(1, min(k, n) + 1):
if b == n:
ans[b >= d] += 1
continue
r = rec(n - b)
ans[1] += r[1]
ans[b >= d] += r[0]
memo[n] = ans
return ans
print(rec(tg)[1] % (10**9 + 7)) | ASSIGN VAR DICT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = int(1000000000.0 + 7)
n, k, d = map(int, input().split())
dp = [[(0) for _ in " " * 2] for _ in range(n + 1)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
dp[i][j >= d] += dp[i - j][0] % mod
dp[i][1] += dp[i - j][1] % mod
print(dp[n][1] % mod) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR BIN_OP STRING NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 10**9 + 7
def countWays(arr, m, N, d):
count = [(0) for i in range(N + 1)]
count[0] = 1
for i in range(1, N + 1):
for j in range(m):
if i >= arr[j] and arr[j] < d:
count[i] += count[i - arr[j]]
count[i] %= mod
return count[N]
def countWays1(arr, m, N):
count = [(0) for i in range(N + 1)]
count[0] = 1
for i in range(1, N + 1):
for j in range(m):
if i >= arr[j]:
count[i] += count[i - arr[j]]
count[i] %= mod
return count[N]
n, k, d = map(int, input().split())
a = [i for i in range(1, k + 1)]
t1 = countWays(a, len(a), n, d)
t2 = countWays1(a, len(a), n)
print((t2 - t1 + mod) % mod) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | a = input()
list_a = list(map(int, a.split()))
n = list_a[0]
k = list_a[1]
d = list_a[2]
solutions = []
for numbers in range(n + 1):
solutions.append(-1)
def dp(n, k, solutions):
if n == 1:
solutions[1] = 1
return 1
if solutions[n] != -1:
return solutions[n]
else:
answer = 0
x = 1
while n - x > 0 and x <= k:
answer += dp(n - x, k, solutions)
x += 1
if n <= k:
answer += 1
solutions[n] = answer
return answer
solutions_copy = []
for numbers in range(n + 1):
solutions_copy.append(-1)
def dp_2(n, k, solutions_copy, d):
if n == 1:
solutions_copy[1] = 1
return 1
if solutions_copy[n] != -1:
return solutions_copy[n]
else:
answer = 0
x = 1
while n - x > 0 and x <= k:
if x < d:
answer += dp_2(n - x, k, solutions_copy, d)
x += 1
else:
x += 1
continue
if n <= k and n < d:
answer += 1
solutions_copy[n] = answer
return answer
if n == d == 1:
print(1)
else:
print((dp(n, k, solutions) - dp_2(n, k, solutions_copy, d)) % (10**9 + 7)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
inf = float("inf")
mod, MOD = 1000000007, 998244353
def get_array():
return list(map(int, sys.stdin.readline().strip().split()))
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def input():
return sys.stdin.readline().strip()
n, k, d = get_ints()
w = [0] * (n + 1)
wot = [0] * (n + 1)
for i in range(1, n + 1):
if i <= k:
w[i] = 1
if i < d:
wot[i] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
continue
w[i] = (w[i] + w[i - j]) % mod
if j < d:
wot[i] = (wot[i] + wot[i - j]) % mod
print((w[n] - wot[n] + mod) % mod) | IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 10**9 + 7
HAVE, NOT_HAVE = 1, 0
n, k, d = map(int, input().split())
dp = [[(0) for _ in range(n + 1)] for _ in range(2)]
dp[NOT_HAVE][0] = 1
for dist in range(1, n + 1):
for weight in range(1, k + 1):
if weight > dist:
break
if weight >= d:
dp[HAVE][dist] += dp[HAVE][dist - weight] + dp[NOT_HAVE][dist - weight]
dp[HAVE][dist] %= MOD
else:
dp[NOT_HAVE][dist] += dp[NOT_HAVE][dist - weight]
dp[NOT_HAVE][dist] %= MOD
dp[HAVE][dist] += dp[HAVE][dist - weight]
dp[HAVE][dist] %= MOD
print(dp[HAVE][n]) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | f, k, d = map(int, input().split())
a = [1]
b = [0]
mod = 1000000007
for i in range(1, f + 1):
m = n = 0
for j in range(1, k + 1):
if i - j > 0 and j < d:
m += a[i - j]
elif i - j > 0 and j >= d:
n += a[i - j]
if i - j > 0:
n += b[i - j]
if i >= d and i <= k:
n += 1
elif i <= k:
m += 1
a.append(m % mod)
b.append(n % mod)
print(b[f]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, v, d = list(map(int, input().split()))
dp = [([0] * 2) for i in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for k in range(1, min(i, v) + 1):
dp[i][0] += dp[i - k][0]
if k >= d:
dp[i][1] += dp[i - k][0]
else:
dp[i][1] += dp[i - k][1]
print(dp[n][1] % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.