結果
問題 | No.645 Count Permutation |
ユーザー |
![]() |
提出日時 | 2017-08-23 21:15:26 |
言語 | C++11 (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 797 bytes |
コンパイル時間 | 554 ms |
コンパイル使用メモリ | 62,428 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-10-15 13:14:56 |
合計ジャッジ時間 | 7,103 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 TLE * 2 -- * 22 |
ソースコード
#include <iostream> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> vl; 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(100005); 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 Div(ll n,ll m){ return n*Pow_mod(m,mod-2)%mod; } ll nPk(ll n,ll k){ return Div(Fact(n),Fact(n-k)); } ll n,l,r; int main(){ cin>>n>>l>>r; vl dp(n); dp[0]=1; ll x=2,res=0; if(!l){ res=n-1; for(int i=1;i<n;i++) (res*=i)%=mod; } while(x<=r){ vl DP(n+1); for(int i=1;i<n;i++){ for(int j=0;j<i;j++){ (DP[i]+=dp[j]*nPk(n-j-2,i-j-1))%=mod; } } dp=DP; if(l<=x) (res+=dp[n-1])%=mod; x*=2; } cout<<res<<endl; }