結果
問題 |
No.411 昇順昇順ソート
|
ユーザー |
|
提出日時 | 2021-09-15 03:02:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 528 ms / 2,000 ms |
コード長 | 885 bytes |
コンパイル時間 | 2,212 ms |
コンパイル使用メモリ | 191,920 KB |
最終ジャッジ日時 | 2025-01-24 14:04:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long int dp[1<<20][20][2]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n,k; cin >> n >> k; k-=1; dp[1<<k][k][0] = 1; for(int i=0;i<(1<<n);i++) { for(int j=0;j<n;j++) { for(int k=0;k<2;k++) { if(dp[i][j][k]==0) continue; if(k==0) { for(int l=0;l<j;l++) { if((i&(1<<l))==0) { dp[i + (1<<l)][l][1] += dp[i][j][k]; } } for(int l=j+1;l<n;l++) { if((i&(1<<l))==0) { dp[i + (1<<l)][l][k] += dp[i][j][k]; } } } else { for(int l=j+1;l<n;l++) { if((i&(1<<l))==0) { dp[i + (1<<l)][l][k] += dp[i][j][k]; } } } } } } long long int res = 0; for(int i=0;i<n;i++) { res += dp[(1<<n)-1][i][1]; } cout << res << '\n'; return 0; }