結果

問題 No.790 ちきんの括弧並べ
ユーザー CleyLCleyL
提出日時 2020-01-29 22:57:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 693 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 64,548 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-14 07:52:33
合計ジャッジ時間 1,366 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 1 ms
4,500 KB
testcase_12 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
long long dp[26][13][13];//i個目でj個の両括弧が使われていてk個の片括弧が使われている
int main(){
    int n;cin>>n;
    dp[0][0][1] = 1;
    for(int i = 1; n*2 > i; i++){
        for(int j = 0; n >= j; j++){
            for(int k = 0; n >= k; k++){
                if(!(j+k))continue;
                if(!k){
                    dp[i][j][k] = dp[i-1][j-1][k+1];
                }else if(!j){
                    dp[i][j][k] = dp[i-1][j][k-1];
                }else{
                    dp[i][j][k] = dp[i-1][j-1][k+1]+dp[i-1][j][k-1];
                }
            }
        }
    }
    cout << dp[n*2-1][n][0] << endl;
    
}
0