답안 #653107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653107 2022-10-25T17:50:40 Z damwuan 캥거루 (CEOI16_kangaroo) C++14
0 / 100
0 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define bit(n,i) ((n>>i)&1)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll maxn=2000+69;
const ll mod=1e9+7;
const ll inf=1e18;
ll n,dp[maxn][maxn],cs,cf;
void add(ll& x , ll y)
{
    x += y;
    if(x >= mod)x -= mod;
}
void sol()
{
    cin >> n>> cs>> cf;
    dp[0][0]=1;
    dp[1][0]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<=n;j++)
        {
            if (i!=cs && i!=cf)
            {
                if (j>0) add(dp[i][j],dp[i-1][j-1]);
                add(dp[i][j],dp[i-1][j+1]*(j+1)%mod*(j+(i>cs)+(i>cf))%mod);
            }
            else
            {
                add(dp[i][j],dp[i-1][j]);
                add(dp[i][j],dp[i-1][j+1]*(j+1)%mod);
            }
            // cout <<i<<' '<<j<<' '<< dp[i][j]<<'\n';
        }
        //dp[1][0]=1;

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


}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t=1;//cin >> t;
    while (t--)
    {
        sol();
    }
}
/*
6 7
0 1 0 2 1 2
1 3
3 6
1 2
2 4
2 5
5 6
1 6

*/

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -