結果

問題 No.140 みんなで旅行
ユーザー kk
提出日時 2021-03-18 18:52:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,042 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 199,248 KB
実行使用メモリ 8,912 KB
最終ジャッジ日時 2023-08-10 15:25:21
合計ジャッジ時間 3,408 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,404 KB
testcase_01 AC 2 ms
5,596 KB
testcase_02 AC 3 ms
5,900 KB
testcase_03 AC 2 ms
5,356 KB
testcase_04 AC 2 ms
5,416 KB
testcase_05 AC 2 ms
5,484 KB
testcase_06 AC 2 ms
5,476 KB
testcase_07 AC 2 ms
5,396 KB
testcase_08 AC 2 ms
5,436 KB
testcase_09 AC 2 ms
5,436 KB
testcase_10 AC 2 ms
5,504 KB
testcase_11 AC 10 ms
8,692 KB
testcase_12 AC 2 ms
5,784 KB
testcase_13 AC 2 ms
5,688 KB
testcase_14 AC 9 ms
8,824 KB
testcase_15 AC 9 ms
8,912 KB
testcase_16 AC 5 ms
7,324 KB
testcase_17 AC 3 ms
6,476 KB
testcase_18 AC 7 ms
8,368 KB
testcase_19 AC 9 ms
8,596 KB
testcase_20 AC 3 ms
6,308 KB
testcase_21 AC 2 ms
5,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1e9 + 7;
long long f[600][600];
long long comb[600][600];

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

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

  int n;
  cin >> n;

  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      if (x + y == 0) f[x][y] = 1;
      else if (y > x) f[x][y] = 0;
      else f[x][y] = (f[x-1][y-1] + y * f[x-1][y]) % MOD;
    }
  }

  for (int i = 0; i <= n; i++) {
    comb[i][0] = comb[i][i] = 1;
    for (int j = 1; j < i; j++)
      comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
  }

  long long ret = 0;
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= x; y++) {
      long long tmp = comb[n][x] * f[x][y] % MOD * modpow(y * (y - 1) % MOD, n - x, MOD) % MOD;
      ret += tmp;
      ret %= MOD;
    }
  }
  cout << ret << endl;
  
  return 0;
}
0