結果

問題 No.790 ちきんの括弧並べ
ユーザー htensai
提出日時 2020-02-05 09:18:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 74,992 KB
実行使用メモリ 54,316 KB
最終ジャッジ日時 2024-09-22 04:06:42
合計ジャッジ時間 4,765 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static long[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        dp = new long[n + 1][n + 1];
        dp[0][0] = 1;
        System.out.println(dfw(n , n));
    }
    
    static long dfw(int open, int close) {
        if (open < 0 || close < 0) {
            return 0;
        }
        if (open < close) {
            return 0;
        }
        if (dp[open][close] != 0) {
            return dp[open][close];
        }
        dp[open][close] = dfw(open - 1, close) + dfw(open, close - 1);
        return dp[open][close];
    }
}
0