Submission #1085623

#TimeUsernameProblemLanguageResultExecution timeMemory
1085623juicy캥거루 (CEOI16_kangaroo)C++17
0 / 100
0 ms460 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2005, M = 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= M) {
    x -= M;
  }
}

int n, s, f;
int dp[N][N];

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

  cin >> n >> s >> f;
  dp[1][1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i == s || i == f) {
        add(dp[i][j], dp[i - 1][j]);
        add(dp[i][j], dp[i - 1][j - 1]);
      } else {
        add(dp[i][j], (long long) dp[i - 1][j + 1] * j % M);
        add(dp[i][j], (long long) dp[i - 1][j - 1] * j % M);
      }
    }
  }
  cout << dp[n][1];
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...