제출 #312146

#제출 시각아이디문제언어결과실행 시간메모리
312146hoangtung_pro캥거루 (CEOI16_kangaroo)C++14
100 / 100
29 ms31872 KiB
#include<bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define bit(s, i) (s & (1<<i))

using namespace std;

const int maxn = 2005;
const int mod = 1e9+7;

typedef long long ll;
typedef pair < int, int > ii;

int n, st, en;

ll dp[maxn][maxn];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(".inp","r",stdin);
    //freopen(".out","w",stdout);

    cin >> n >> st >> en;

    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;

    for(int i=1;i<=n;++i)
    for(int j=1;j<=i;++j)
    {
        if(i == st || i == en)
        {
            dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
//            cout << i << ' ' << j << ' ' << dp[i][j] << endl;
            continue;
        }

        ll cur = dp[i - 1][j + 1] * j;
        dp[i][j] = (dp[i][j] + cur) % mod;
        int x = j;
        if(st < i) -- x;
        if(en < i) -- x;
        cur = dp[i - 1][j - 1] * x;
        dp[i][j] = (dp[i][j] + cur) % mod;
//        cout << i << ' ' << j << ' ' << dp[i][j] << endl;
    }
    cout << dp[n][1];
}






#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...