結果

問題 No.411 昇順昇順ソート
ユーザー beet
提出日時 2018-07-30 14:10:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,152 ms / 2,000 ms
コード長 496 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 167,368 KB
実行使用メモリ 331,288 KB
最終ジャッジ日時 2024-09-13 19:28:30
合計ジャッジ時間 7,670 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0