#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Number/combination.hpp" #include template struct Combination { int max_n; std::vector f, invf; explicit Combination(int n) : max_n(n), f(n + 1), invf(n + 1) { f[0] = 1; for (int i = 1; i <= n; ++i) { f[i] = f[i - 1] * i; } invf[max_n] = f[max_n].inv(); for (int i = max_n - 1; i >= 0; --i) { invf[i] = invf[i + 1] * (i + 1); } } T fact(int n) const { return n < 0 ? T(0) : f[n]; } T invfact(int n) const { return n < 0 ? T(0) : invf[n]; } T perm(int a, int b) const { return a < b || b < 0 ? T(0) : f[a] * invf[a - b]; } T binom(int a, int b) const { return a < b || b < 0 ? T(0) : f[a] * invf[a - b] * invf[b]; } }; #line 2 "main.cpp" #include #include #include #line 6 "main.cpp" using namespace std; using mint = atcoder::modint1000000007; const Combination C(100000); void solve() { int n, mp, mq, l; cin >> n >> mp >> mq >> l; auto dp = vector(n + 1, vector(mq + 1, mint(0))); dp[0][0] = 1; // i人にqを合計j個配った for (int r = n; r--;) { int s; cin >> s; for (int i = n; i >= 1; --i) { auto pdp = dp[i - 1]; pdp.insert(pdp.begin(), 0); // 1個以上s個以下配る // 累積和で遷移 for (int j = 0; j <= mq; ++j) { dp[i][j] += pdp[j] - pdp[max(0, j - s)]; pdp[j + 1] += pdp[j]; } } } mint ans = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= mq; ++j) { // 残ったpの個数 int p = mp - (i * l - j); if (p >= 0) { // 残ったpの分配 ans += dp[i][j] * C.binom(n + p - 1, n - 1); } } } cout << ans.val() << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }