結果

問題 No.140 みんなで旅行
ユーザー motimoti
提出日時 2015-04-16 15:56:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 948 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 66,416 KB
実行使用メモリ 11,744 KB
最終ジャッジ日時 2023-09-17 20:53:35
合計ジャッジ時間 1,833 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
11,604 KB
testcase_01 AC 11 ms
11,444 KB
testcase_02 AC 12 ms
11,452 KB
testcase_03 AC 11 ms
11,472 KB
testcase_04 AC 11 ms
11,500 KB
testcase_05 AC 12 ms
11,452 KB
testcase_06 AC 12 ms
11,480 KB
testcase_07 AC 12 ms
11,612 KB
testcase_08 AC 11 ms
11,536 KB
testcase_09 AC 11 ms
11,440 KB
testcase_10 AC 11 ms
11,484 KB
testcase_11 AC 13 ms
11,440 KB
testcase_12 AC 12 ms
11,744 KB
testcase_13 AC 11 ms
11,468 KB
testcase_14 AC 12 ms
11,424 KB
testcase_15 AC 13 ms
11,432 KB
testcase_16 AC 12 ms
11,536 KB
testcase_17 AC 12 ms
11,508 KB
testcase_18 AC 12 ms
11,420 KB
testcase_19 AC 13 ms
11,580 KB
testcase_20 AC 12 ms
11,544 KB
testcase_21 AC 11 ms
11,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int const MOD = 1e9+7;

int main() {

  ll N; cin >> N;
  vector<vector<ll>> dp(600, vector<ll>(600));

  REP(i, 1, 600) {
    dp[i][1] = 1;
    REP(j, 2, 600) {
      (dp[i][j] = dp[i-1][j-1] + j*dp[i-1][j]) %= MOD;
    }
  }

  vector<vector<ll>> comb(600, vector<ll>(600));
  rep(i, 600) {
    comb[i][0] = 1;
    REP(j, 1, i+1) {
      (comb[i][j] = comb[i-1][j] + comb[i-1][j-1]) %= MOD;
    }
  }

  // (i*(i-1)) ^ j を計算
  vector<vector<ll>> prepow(600, vector<ll>(600));
  rep(i, 600) {
    prepow[i][0] = 1;
    rep(j, 600) {
      (prepow[i][j+1] = prepow[i][j] * i*(i-1)) %= MOD;
    }
  }

  ll ans = 0;
  REP(i, 1, N+1) REP(j, 1, i+1) {
    (ans += comb[N][i] * dp[i][j] % MOD * prepow[j][N-i] % MOD) %= MOD;
  }

  cout << ans << endl;

  return 0;
}
0