結果
問題 |
No.93 ペガサス
|
ユーザー |
![]() |
提出日時 | 2025-09-08 12:16:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 33 ms / 5,000 ms |
コード長 | 1,587 bytes |
コンパイル時間 | 1,532 ms |
コンパイル使用メモリ | 162,212 KB |
実行使用メモリ | 35,088 KB |
最終ジャッジ日時 | 2025-09-08 12:16:06 |
合計ジャッジ時間 | 2,781 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#include<bits/stdc++.h> #define int long long using namespace std; const int N=1e3+10; const int mod=1e9+7; int n,dp[N][N][2][2]; signed main() { ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n; if(n==1) { cout<<1<<'\n'; return 0; } dp[2][0][0][0]=2; for(int i=3;i<=n;i++) { for(int j=0;j<=n;j++) { for(int k1=0;k1<2;k1++) { for(int k2=0;k2<2;k2++) { if(j!=0) { if(k1==1) { dp[i][j-1][0][0]+=dp[i-1][j][k1][k2]; } dp[i][j-1][0][k1]+=dp[i-1][j][k1][k2]*(j-k1-k2); } if(k2==1) { dp[i][j][1][k1]+=dp[i-1][j][k1][k2]; } dp[i][j][0][k1]+=dp[i-1][j][k1][k2]*(i-j-2+k2); dp[i][j+1][1][k1]+=dp[i-1][j][k1][k2]*(2-k2); } } } for(int j=0;j<=n;j++) { for(int k1=0;k1<2;k1++) { for(int k2=0;k2<2;k2++) { // if(dp[i][j][k1][k2]!=0) // { // cout<<i<<" "<<j<<" "<<k1<<" "<<k2<<" "<<dp[i][j][k1][k2]<<'\n'; // } dp[i][j][k1][k2]%=mod; } } } } cout<<dp[n][0][0][0]<<'\n'; return 0; }