제출 #878331

#제출 시각아이디문제언어결과실행 시간메모리
878331Erfan1386YTents (JOI18_tents)C++17
100 / 100
91 ms70996 KiB
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << endl;
#define kill(x) {cout << x << '\n'; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 8e18, mod = 1e9 + 7, delta = 1e8, SQ = 700; //998244353

using namespace std;

const ll N = 3e3 + 10, LG = 20;
ll dp[N][N];

int32_t main() {
  fast_io; 
  int n, m;
  cin >> n >> m;
  dp[0][0] = 1;
  dp[1][1] = 5;
  for (int i = 1; i <= n; i++) dp[i][0] = 1;
  for (int i = 1; i <= m; i++) dp[0][i] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1 && j == 1) continue;
      dp[i][j] = dp[i - 1][j];
      dp[i][j] += (4 * j * dp[i - 1][j - 1] % mod);
      dp[i][j] %= mod;
      if (i >= 2) dp[i][j] += (j * (i - 1) * dp[i - 2][j - 1] % mod);
      dp[i][j] %= mod;
      if (j >= 2) dp[i][j] += (j * (j - 1) / 2 * dp[i - 1][j - 2] % mod);
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m] - 1 << '\n';
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...