結果

問題 No.1011 Infinite Stairs
ユーザー zeronosu77108
提出日時 2020-03-21 00:27:37
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 1,882 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 123,520 KB
実行使用メモリ 216,960 KB
最終ジャッジ日時 2024-07-17 11:56:19
合計ジャッジ時間 2,593 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

using int64 = long long;

const int MOD = 1000000007;
struct mint {
    int64 x;
    mint(const int64 x1=0) { x = x1%MOD; };

    mint& operator++(int n) { x+=1; return *this; };
    mint& operator--(int n) { x-=1; return *this; };
    mint& operator=(int64 n) { x=n%MOD; return *this; };
    mint& operator--() {x-=1; return *this; };
    mint& operator+=(const mint a) { if ( (x+=a.x) >= MOD) x-=MOD; return *this; }
    mint& operator-=(const mint a) { if ( (x+= MOD-a.x) >= MOD) x-= MOD; return *this; }
    mint& operator*=(const mint a) { (x*=a.x) %= MOD; return *this; }
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
    mint inv() const { return pow(MOD-2);}
    friend ostream& operator<<(ostream &os, const mint a) noexcept { return os << a.x; }
    constexpr bool operator == (const mint& r) const noexcept { return this->x == r.x; }
    constexpr bool operator != (const mint& r) const noexcept { return this->x != r.x; }
    mint pow(long long t) const {
        if (!t) return mint(1);
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }
};

int main() {
    int n, d, k;
    cin >> n >> d >> k;
    vector<vector<mint>> dp(n + 1, vector<mint>(k + d + 1, 0));
    dp[0][0] = 1;

    for (int i=0; i<n; i++) {
        for (int j=0; j<=d*n; j++) {
            if (j > k-1) continue;
            dp[i+1][j+1] += dp[i][j];
            dp[i+1][j+1+d] -= dp[i][j];
            dp[i+1][j+1] += dp[i+1][j];
        }
    }

    cout << dp[n][k] << endl;
}
0