加载中...

数学公式

组合数

image-20230326214621064

import java.util.Scanner;

public class 求组合数 {
	public static void main(String[] args) {
		int n, m;
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		m = scanner.nextInt();
		int res = combination(n, m);
		System.out.println(res);
	}

	private static int combination(int n, int m) {
		int[][] dp = new int[n + 1][m + 1];
		for (int i = 0; i <= n; i++) {
			dp[i][0] = 1;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
			}
		}
		return dp[n][m];
	}

}

image-20230326215932224

posted @ 2023-03-26 21:47  ChuenSan  阅读(18)  评论(0编辑  收藏  举报