algo

https://www.acmicpc.net/problem/13703


//package cote;

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
    //	System.setIn(new FileInputStream("input.txt"));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int k = Integer.parseInt(st.nextToken()); 
        int n = Integer.parseInt(st.nextToken()); 

       
        if (k == 0) {
            System.out.println(0);
            return;
        }

        
        long[][] dp = new long[n + 1][k + n + 2];

        
        dp[0][k] = 1;

        for (int i = 0; i < n; i++) {
            for (int h = 1; h <= k + n; h++) {
                
                if (dp[i][h] == 0) continue;

                
                if (h - 1 > 0) {
                    dp[i + 1][h - 1] += dp[i][h];
                }
                
                dp[i + 1][h + 1] += dp[i][h];
            }
        }

        
        long totalSurvivors = 0;
        for (int h = 1; h <= k + n; h++) {
            totalSurvivors += dp[n][h];
        }

        System.out.println(totalSurvivors);
    }
}

results matching ""

    No results matching ""