結果

問題 No.44 DPなすごろく
ユーザー villachvillach
提出日時 2017-10-11 09:54:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 149 ms / 5,000 ms
コード長 933 bytes
コンパイル時間 3,376 ms
コンパイル使用メモリ 77,460 KB
実行使用メモリ 58,968 KB
最終ジャッジ日時 2024-04-28 15:51:26
合計ジャッジ時間 7,742 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
54,080 KB
testcase_01 AC 141 ms
54,012 KB
testcase_02 AC 149 ms
58,752 KB
testcase_03 AC 144 ms
55,828 KB
testcase_04 AC 147 ms
53,976 KB
testcase_05 AC 142 ms
56,300 KB
testcase_06 AC 144 ms
56,392 KB
testcase_07 AC 142 ms
56,140 KB
testcase_08 AC 141 ms
56,288 KB
testcase_09 AC 135 ms
54,156 KB
testcase_10 AC 144 ms
56,328 KB
testcase_11 AC 144 ms
55,912 KB
testcase_12 AC 146 ms
56,200 KB
testcase_13 AC 141 ms
55,968 KB
testcase_14 AC 145 ms
58,756 KB
testcase_15 AC 142 ms
56,244 KB
testcase_16 AC 144 ms
56,060 KB
testcase_17 AC 134 ms
54,164 KB
testcase_18 AC 142 ms
55,868 KB
testcase_19 AC 146 ms
58,968 KB
testcase_20 AC 133 ms
54,048 KB
testcase_21 AC 133 ms
54,084 KB
testcase_22 AC 133 ms
54,040 KB
testcase_23 AC 143 ms
58,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class N44 {
	private int n;
	public long c;
	public long[][] dp;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		N44 hoge = new N44(n);
		long i = hoge.solve(0, 0);
		System.out.println(i);
	}
	
	N44(int n){
		this.n = n;
		this.dp = new long[n][10000];
		for(int i = 0;i < n;++i){
			for(int j = 0;j < 10000;++j){
				dp[i][j] = -1;
			}
		}
	}
	
	public long solve(int step, int count){
		long a, b;
		if(step + 1 == n){
			return count + 1;
		}else if(step + 2 == n){
			return count + 2;
		}else if(step >= n){
			return 0;
		}
		if(dp[step + 1][count] != -1){
			a = dp[step + 1][count];
		}else{
			a = solve(step + 1, count);
			dp[step + 1][count] = a;
		}
		if(dp[step + 2][count] != -1){
			b = dp[step + 2][count];
		}else{
			b = solve(step + 2, count);
			dp[step + 2][count] = b;
		}
		return a + b;
	}
}
0