luoheng
10/22/2019 - 10:53 AM

划分数

// 划分数
func divNM(n, m, M int) int {
	dp := make([][]int, m+1)
	for i := 0; i < m+1; i++ {
		dp[i] = make([]int, n+1)
	}
	dp[0][0] = 1
	for i := 1; i <= m; i++ {
		for j := 0; j <= n; j++ {
			if j >= i {
				dp[i][j] = (dp[i-1][j] + dp[i][j-i]) % M
			} else {
				dp[i][j] = dp[i-1][j]
			}
		}
	}
	return dp[m][n]
}