結果
問題 | No.503 配列コレクション |
ユーザー |
![]() |
提出日時 | 2017-02-17 15:35:39 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 190 ms / 2,000 ms |
コード長 | 907 bytes |
コンパイル時間 | 691 ms |
コンパイル使用メモリ | 63,272 KB |
実行使用メモリ | 38,360 KB |
最終ジャッジ日時 | 2024-12-30 22:59:04 |
合計ジャッジ時間 | 2,525 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
#include <iostream> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; const ll mod=1e9+7; ll Pow_mod(ll n,ll p){ ll r=1; for(;p>0;p>>=1){ if(p&1) r=(r*n)%mod; n=(n*n)%mod; } return r; } vl fact(1000000); ll Fact(ll n){ if(fact[n]) return fact[n]; if(!n) return fact[n]=1; return fact[n]=Fact(n-1)*n%mod; } ll Division_mod(ll n,ll m){ return n*Pow_mod(m,mod-2)%mod; } ll Combination(ll n,ll k){ return Division_mod(Fact(n),Fact(n-k)*Fact(k)%mod); } ll N,K,D; int main(){ cin>>N>>K>>D; ll num=(N-1)/(K-1),len=N-num*(K-1); if(D==1){ cout<<len<<endl; return 0; } vvl dp(len+1,vl(num+1)); for(int i=0;i<=num;i++) dp[1][i]=Pow_mod(D,i); for(int i=2;i<=len;i++){ ll x=0,y=0; for(int j=0;j<=num;j++){ x=(x+dp[i-1][j])%mod; y=(y*D+Combination(i+j-2,j))%mod; dp[i][j]=(x+y)%mod; } } cout<<dp[len][num]<<endl; }