답안 #127460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127460 2019-07-09T11:52:03 Z RockyB Tents (JOI18_tents) C++17
100 / 100
456 ms 65528 KB
#include <bits/stdc++.h>

#define rep(a, b, c) for (int a = (b); (a) <= (c); a++)
#define per(a, b, c) for (int a = (b); (a) >= (c); a--)

#define nl '\n'
#define ioi exit(0);

const int mod = (int)1e9 + 7;
const int N = (int)1e4;

using namespace std;

void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
int sum(int x, int y) {
  add(x, y);
  return x;
}
int bp(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = res * 1ll * x % mod;
    x = x * 1ll * x % mod, y >>= 1;
  }
  return res;
}

int n, m;
int f[N], rv[N];

int dp[3001][3001];
int cnk(int x, int y) {
  return (f[x] * 1ll * rv[x - y] % mod) * 1ll * rv[y] % mod;
}
int ank(int x, int y) {
  return f[x] * 1ll * rv[x - y] % mod;
}
int calc(int v = n, int free = m) {
  if (!v) return 1;
  if (~dp[v][free]) return dp[v][free];
  int res = calc(v - 1, free);
  // put < or > or ^ or v
  if (free > 0) add(res, calc(v - 1, free - 1) * 1ll * free * 4 % mod);
  // connect v and ^
  // if (must > 0) add(res, calc(v + 1, free, must - 1) * 1ll * must % mod);
  // open v
  // if (free > 0) add(res, calc(v + 1, free - 1, must + 1) * 1ll * free % mod);
  // connect > and <
  if (free > 1) add(res, calc(v - 1, free - 2) * 1ll * cnk(free, 2) % mod);
  return dp[v][free] = res;
}

int put[N][N];
int main() {
  #ifdef IOI
    freopen ("in.txt", "r", stdin);
    freopen ("slow.out", "w", stdout);
  #endif
  f[0] = rv[0] = 1;
  rep(i, 1, N - 1) {
    f[i] = f[i - 1] * 1ll * i % mod;
    rv[i] = bp(f[i], mod - 2);
  }
  cin >> n >> m;
  //cout << calc()
  memset(dp, -1, sizeof(dp));
  int ans = sum(calc(), -1);


  {
    put[0][0] = 1;
    rep(i, 1, m) {
      rep(j, 0, i) {
        put[i][j] = put[i - 1][j];
        if (j > 0) add(put[i][j], put[i - 1][j - 1] * 1ll * cnk(n - 2 * (j - 1), 2) % mod);
      }
    }
    //cerr << put[3][2] << nl;
  }
  rep(i, 1, n / 2) {
    int take = put[m][i]; 
    // ans = 0;
    if (i <= m) add(ans, take * 1ll * calc(n - 2 * i, m - i) % mod);
    //cerr << ans << ' ' << take << ' ' << calc(n - 2 * i, m - i) << nl;
  }
  cout << ans << nl;
  ioi
}

/*

5116 0
3720 1
450 2

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 35704 KB Output is correct
2 Correct 34 ms 36472 KB Output is correct
3 Correct 33 ms 35704 KB Output is correct
4 Correct 34 ms 35656 KB Output is correct
5 Correct 35 ms 36984 KB Output is correct
6 Correct 35 ms 36088 KB Output is correct
7 Correct 35 ms 36696 KB Output is correct
8 Correct 34 ms 35960 KB Output is correct
9 Correct 34 ms 35704 KB Output is correct
10 Correct 36 ms 36344 KB Output is correct
11 Correct 35 ms 37012 KB Output is correct
12 Correct 37 ms 37112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 35704 KB Output is correct
2 Correct 34 ms 36472 KB Output is correct
3 Correct 33 ms 35704 KB Output is correct
4 Correct 34 ms 35656 KB Output is correct
5 Correct 35 ms 36984 KB Output is correct
6 Correct 35 ms 36088 KB Output is correct
7 Correct 35 ms 36696 KB Output is correct
8 Correct 34 ms 35960 KB Output is correct
9 Correct 34 ms 35704 KB Output is correct
10 Correct 36 ms 36344 KB Output is correct
11 Correct 35 ms 37012 KB Output is correct
12 Correct 37 ms 37112 KB Output is correct
13 Correct 64 ms 49824 KB Output is correct
14 Correct 34 ms 35832 KB Output is correct
15 Correct 286 ms 51972 KB Output is correct
16 Correct 66 ms 46712 KB Output is correct
17 Correct 88 ms 49400 KB Output is correct
18 Correct 102 ms 44664 KB Output is correct
19 Correct 340 ms 54776 KB Output is correct
20 Correct 268 ms 53348 KB Output is correct
21 Correct 199 ms 52600 KB Output is correct
22 Correct 184 ms 46980 KB Output is correct
23 Correct 115 ms 39132 KB Output is correct
24 Correct 456 ms 65528 KB Output is correct
25 Correct 338 ms 59276 KB Output is correct
26 Correct 382 ms 61384 KB Output is correct
27 Correct 439 ms 65020 KB Output is correct