結果
問題 |
No.411 昇順昇順ソート
|
ユーザー |
![]() |
提出日時 | 2020-12-03 16:59:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,404 ms / 2,000 ms |
コード長 | 496 bytes |
コンパイル時間 | 2,176 ms |
コンパイル使用メモリ | 191,056 KB |
最終ジャッジ日時 | 2025-01-16 14:29:07 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; //INSERT ABOVE HERE Int n,k; Int dp[2][20][1<<20]; int dfs(Int f,Int p,Int b){ Int &res=dp[f][p][b]; if(~res) return res; if(b+1==(1<<n)) return f; res=0; for(Int i=0;i<n;i++){ if((b>>i)&1) continue; Int nf=p>i,nb=b|(1<<i); if(nf&&f) continue; nf|=f; res+=dfs(nf,i,nb); } return res; }; signed main(){ cin>>n>>k; memset(dp,-1,sizeof(dp)); k--; cout<<dfs(0,k,1<<k)<<endl; return 0; }