結果

問題 No.140 みんなで旅行
ユーザー h_nosonh_noson
提出日時 2016-06-05 19:09:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 951 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 65,656 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-17 05:02:39
合計ジャッジ時間 1,595 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 7 ms
10,624 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 8 ms
10,624 KB
testcase_15 AC 7 ms
10,368 KB
testcase_16 AC 5 ms
7,936 KB
testcase_17 AC 3 ms
6,528 KB
testcase_18 AC 7 ms
9,728 KB
testcase_19 AC 7 ms
9,984 KB
testcase_20 AC 3 ms
6,144 KB
testcase_21 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

ll dp[556][556];
ll comb[556][556];
ll power[556][556];

int main(void) {
    int i, j, n;
    cin >> n;

    dp[0][0] = 1;
    REP (i,1,n) REP (j,1,i)
        if (j > 0) dp[i][j] = (dp[i-1][j-1] + j * dp[i-1][j]) % MOD;

    comb[0][0] = 1;
    REP (i,1,n) rep (j,i+1)
        comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % MOD;

    REP (i,1,n) {
        power[i][0] = 1;
        REP (j,1,n)
            power[i][j] = power[i][j-1] * i * (i-1) % MOD;
    }

    int ans = 0;
    REP (i,1,n) REP (j,1,i)
        ans = (ans + comb[n][i] * dp[i][j] % MOD * power[j][n-i]) % MOD;
    cout << ans << endl;
    return 0;
}
0