結果
| 問題 |
No.140 みんなで旅行
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2018-12-13 18:59:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 156 ms / 5,000 ms |
| コード長 | 1,680 bytes |
| コンパイル時間 | 1,283 ms |
| コンパイル使用メモリ | 98,116 KB |
| 実行使用メモリ | 15,488 KB |
| 最終ジャッジ日時 | 2024-09-25 04:35:44 |
| 合計ジャッジ時間 | 2,714 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / 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;
ll powmod(ll a, ll k){
ll ap=a, ans=1;
while(k>0){
if(k%2==1){
ans*=ap;
ans%=MOD;
}
ap=ap*ap;
ap%=MOD;
k/=2;
}
return ans;
}
ll inv(ll a){
return powmod(a, MOD-2);
}
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 f[556]; f[0]=1;
for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
ll invf[556];
invf[n]=inv(f[n]);
for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
ll a[556][556];
for(int x=1; x<=n; x++){
for(int y=x; y<=n; y++){
a[x][y]=0;
for(int i=0; i<x; i++){
if(i&1) a[x][y]+=(MOD-comb[x][i]*pow[x-i][y]%MOD);
else a[x][y]+=(comb[x][i]*pow[x-i][y]%MOD);
a[x][y]%=MOD;
}
a[x][y]=a[x][y]*invf[x]%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;
}
chocorusk