// SEQCOUNT Solution. Written by Sergey Kulik #include #include using namespace std; #define mod 1000000007 #define maxn 100000 + 5 int n, m, k, t, i, j, dp[2][maxn], ac[maxn], l; void upd (int &a, int b) { a += b; if (a >= mod) a -= mod; } int main () { scanf("%d %d %d", &n, &m, &k); for(i = 1; i <= m; i++) t += i; if (t > n) { // If the minimal possible sum is greater than N, there is no way to construct a nice sequence puts("0"); return 0; } for(i = 1; i <= n; i++) dp[0][i] = 0; dp[0][0] = 1; for(i = 1; i <= m; i++) { for(j = 0; j < m - i + 1; j++) ac[j] = 0; for(j = 0; j <= n; j++) dp[1 - l][j] = 0; for(j = 0; j <= n; j++) { dp[1 - l][j] = ac[j % (m - i + 1)]; // all the requred summands for this state will have equal remainder modulo (m - i + 1) upd(ac[j % (m - i + 1)], dp[l][j]); // add the current state for the further updates if (j - (m - i + 1) * (k) >= 0) upd(ac[j % (m - i + 1)], mod - dp[l][j - (m - i + 1) * (k)]); // we shouldn't consider the differences larger than k } l ^= 1; } printf("%d\n", dp[l][n]); return 0; }