結果
問題 |
No.411 昇順昇順ソート
|
ユーザー |
![]() |
提出日時 | 2018-07-30 14:08:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,378 ms / 2,000 ms |
コード長 | 604 bytes |
コンパイル時間 | 1,821 ms |
コンパイル使用メモリ | 169,588 KB |
実行使用メモリ | 331,220 KB |
最終ジャッジ日時 | 2024-09-13 19:28:18 |
合計ジャッジ時間 | 10,012 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; //INSERT ABOVE HERE Int dp[2][20][1<<20]; signed main(){ Int n,k; cin>>n>>k; memset(dp,-1,sizeof(dp)); function<Int(Int, Int, Int)> dfs= [&](Int f,Int p,Int b)->Int{ 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); } //cout<<f<<" "<<p<<" "<<b<<":"<<res<<endl; return res; }; k--; cout<<dfs(0,k,1<<k)<<endl; return 0; }