QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#787050#9561. 树数叔术caijianhong100 ✓981ms22452kbC++233.1kb2024-11-27 09:10:502024-11-27 09:10:50

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 09:10:50]
  • 评测
  • 测评结果:100
  • 用时:981ms
  • 内存:22452kb
  • [2024-11-27 09:10:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define endl "\n"
#define debug(...) void(0)
#endif
using LL = long long;
template <int id>
struct modint {// {{{
  static int mod;
  static unsigned umod() { return mod; }
  unsigned v;
  modint() = default;
  template <class T, std::enable_if_t<std::is_integral<T>::value, int> = 0>
  modint(const T &_y)
      : v((unsigned)(_y % mod + (std::is_signed<T>() && _y < 0 ? mod : 0))) {}
  friend int raw(const modint &self) { return self.v; }
  friend std::ostream &operator<<(std::ostream &os, const modint &self) {
    return os << raw(self);
  }
  modint &operator+=(const modint &rhs) {
    v += rhs.v;
    if (v >= umod()) v -= umod();
    return *this;
  }
  modint &operator-=(const modint &rhs) {
    v -= rhs.v;
    if (v >= umod()) v += umod();
    return *this;
  }
  modint &operator*=(const modint &rhs) {
    v = (unsigned)(1ull * v * rhs.v % umod());
    return *this;
  }
  static int inverse(int a, int b) {
    assert(a);
    return a == 1 ? 1 : b - 1ll * inverse(b % a, a) * b / a;
  }
  modint &operator/=(const modint &rhs) {
    return *this *= inverse(rhs.v, mod);
  }
  friend modint qpow(modint a, LL b) {
    if (b < 0) b = -b, a = 1 / a;
    modint r = 1;
    for (; b; b >>= 1, a *= a)
      if (b & 1) r *= a;
    return r;
  }
  friend modint operator+(modint lhs, const modint &rhs) { return lhs += rhs; }
  friend modint operator-(modint lhs, const modint &rhs) { return lhs -= rhs; }
  friend modint operator*(modint lhs, const modint &rhs) { return lhs *= rhs; }
  friend modint operator/(modint lhs, const modint &rhs) { return lhs /= rhs; }
  friend bool operator==(const modint &lhs, const modint &rhs) {
    return lhs.v == rhs.v;
  }
  friend bool operator!=(const modint &lhs, const modint &rhs) {
    return lhs.v != rhs.v;
  }
  explicit operator bool() const { return v != 0; }
};// }}}
template <int id> int modint<id>::mod;
using mint = modint<-1>;
int N, V;
mint f[210][210][210], fac[210], binom[210][210];
int main() {
#ifndef LOCAL
  cin.tie(nullptr)->sync_with_stdio(false);
#endif
  cin >> N >> V >> mint::mod;
  if (V >= N) return cout << 0 << endl, 0;
  fac[0] = 1;
  for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i;
  for (int i = 0; i <= N; i++) {
    binom[i][0] = 1;
    for (int j = 1; j <= i; j++) binom[i][j] = binom[i - 1][j] + binom[i - 1][j - 1];
  }
  f[0][1][0] = 1;
  for (int v = 1; v <= V; v++) {
    for (int i = 1; i <= N; i++) {
      for (int c = 0; c <= i; c++) {
        // f[v - 1][i][c]
        for (int d = 1; d <= c; d++) {
          f[v][i][c - d] += f[v - 1][i][c] * binom[c][d];
        }
        for (int d = 1; d <= N - i; d++) {
          f[v][i + d][c + d - 1] += f[v - 1][i][c] * binom[i + d][d] * fac[d] * i;
        }
      }
    }
  }
  for (int v = 0; v <= V; v++) {
    for (int i = 1; i <= N; i++) {
      for (int c = 0; c <= i; c++) {
        if (f[v][i][c]) debug("f[%d][%d][%d] = %d\n", v, i, c, raw(f[v][i][c]));
      }
    }
  }
  cout << f[V][N][0] << endl;
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3612kb

input:

1 1 624295285

output:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3568kb

input:

4 684813415 564954712

output:

0

result:

ok single line: '0'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3656kb

input:

4 2 844826878

output:

24

result:

ok single line: '24'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3636kb

input:

4 17724073 252218682

output:

0

result:

ok single line: '0'

Test #5:

score: 5
Accepted
time: 0ms
memory: 3608kb

input:

4 3 697681963

output:

384

result:

ok single line: '384'

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 0ms
memory: 3620kb

input:

6 4 956647977

output:

238320

result:

ok single line: '238320'

Test #7:

score: 15
Accepted
time: 0ms
memory: 3616kb

input:

6 450615260 491361886

output:

0

result:

ok single line: '0'

Test #8:

score: 15
Accepted
time: 0ms
memory: 3624kb

input:

6 5 339344353

output:

933120

result:

ok single line: '933120'

Test #9:

score: 15
Accepted
time: 0ms
memory: 3684kb

input:

6 3 842228619

output:

23760

result:

ok single line: '23760'

Test #10:

score: 15
Accepted
time: 0ms
memory: 3672kb

input:

6 5 331699652

output:

933120

result:

ok single line: '933120'

Subtask #3:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 7ms
memory: 4724kb

input:

48 26 424594716

output:

362283012

result:

ok single line: '362283012'

Test #12:

score: 30
Accepted
time: 0ms
memory: 3576kb

input:

49 1000000000 738885247

output:

0

result:

ok single line: '0'

Test #13:

score: 30
Accepted
time: 10ms
memory: 5340kb

input:

48 39 688951620

output:

598399200

result:

ok single line: '598399200'

Test #14:

score: 30
Accepted
time: 0ms
memory: 3632kb

input:

50 476039414 292870080

output:

0

result:

ok single line: '0'

Test #15:

score: 30
Accepted
time: 9ms
memory: 5792kb

input:

50 48 245196368

output:

123576912

result:

ok single line: '123576912'

Subtask #4:

score: 50
Accepted

Test #16:

score: 50
Accepted
time: 0ms
memory: 3616kb

input:

150 526250070 197316869

output:

0

result:

ok single line: '0'

Test #17:

score: 50
Accepted
time: 755ms
memory: 18368kb

input:

149 116 671784452

output:

18945228

result:

ok single line: '18945228'

Test #18:

score: 50
Accepted
time: 888ms
memory: 21480kb

input:

146 144 906402626

output:

438777234

result:

ok single line: '438777234'

Test #19:

score: 50
Accepted
time: 895ms
memory: 21592kb

input:

147 143 705666477

output:

70408701

result:

ok single line: '70408701'

Test #20:

score: 50
Accepted
time: 981ms
memory: 22452kb

input:

150 147 453481175

output:

336290325

result:

ok single line: '336290325'