当前位置:编程学习 > C/C++ >>

HDU2151

[java] 
 
import java.util.*; 
 
public class HDU2151 { 
 
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in); 
        int n, p, m, t; 
        int arr[][]; 
        while (sc.hasNext()) { 
            n = sc.nextInt(); 
            p = sc.nextInt(); 
            m = sc.nextInt(); 
            t = sc.nextInt(); 
 
            arr = new int[101][101]; 
            arr[0][p] = 1; 
            for (int i = 1; i <= m; i++) { 
                for (int j = n; j >= 1; j--) { 
                    if (j + 1 > n) 
                        arr[i][j] += arr[i - 1][j - 1]; 
                    else if (j - 1 < 0) 
                        arr[i][j] += arr[i - 1][j + 1]; 
                    else 
                        arr[i][j] += (arr[i - 1][j - 1] + arr[i - 1][j + 1]); 
 
                } 
            } 
            System.out.println(arr[m][t]); 
        } 
 
    } 
 
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,