結果
問題 |
No.140 みんなで旅行
|
ユーザー |
![]() |
提出日時 | 2018-12-13 19:07:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 17 ms / 5,000 ms |
コード長 | 1,164 bytes |
コンパイル時間 | 1,012 ms |
コンパイル使用メモリ | 96,352 KB |
実行使用メモリ | 15,488 KB |
最終ジャッジ日時 | 2024-09-25 04:35:52 |
合計ジャッジ時間 | 1,732 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> using namespace std; typedef long long int ll; typedef pair<int, int> P; const ll MOD=1e9+7; int main() { int n; cin>>n; ll pow[556][1111]; for(ll i=0; i<=n; i++){ pow[i][0]=1; for(int j=1; j<=2*n; j++){ pow[i][j]=pow[i][j-1]*i%MOD; } } ll comb[556][556]={}; comb[0][0]=1; for(int i=1; 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; } } ll a[556][556]; fill(a[1]+1, a[1]+n+1, 1); for(ll x=2; x<=n; x++){ a[x][x]=1; for(int y=x+1; y<=n; y++){ a[x][y]=(a[x-1][y-1]+x*a[x][y-1])%MOD; } } ll b[556][556]; for(int x=1; x<=n; x++){ for(int y=x; y<=n; y++){ b[x][y]=pow[x][n-y]*pow[x-1][n-y]%MOD*a[x][y]%MOD; } } ll ans=0; for(int x=1; x<=n; x++){ for(int y=x; y<=n; y++){ ans+=(comb[n][y]*b[x][y]%MOD); ans%=MOD; } } cout<<ans<<endl; return 0; }