結果
| 問題 |
No.2530 Yellow Cards
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2023-11-03 23:49:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 771 bytes |
| コンパイル時間 | 1,954 ms |
| コンパイル使用メモリ | 193,140 KB |
| 最終ジャッジ日時 | 2025-02-17 19:00:32 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 3 WA * 14 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
ll dp[5050][5050];
ll modpow(ll x,ll n){
x%=MOD;
ll ans=1;
while(n){
if(n&1) ans=ans*x%MOD;
x=x*x%MOD;
n/=2;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,k;
cin>>n>>k;
ll a=modpow(n,MOD-2);
dp[0][0]=n;
for(int i=0;i<k;i++){
for(int j=0;j<=n;j++){
if(dp[i][j]==0) continue;
if(j) dp[i+1][j-1]=(dp[i+1][j-1]+(dp[i][j]+1)*j%MOD*a%MOD)%MOD;
dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*(n-j)%MOD*a%MOD)%MOD;
}
}
ll ans=0;
for(int j=0;j<=n;j++) ans=(ans+dp[k][j]);
cout<<ans<<endl;
return 0;
}
umezo