题解 | #放苹果#
放苹果
https://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf
动态规划
#include <stdio.h> static int apple(int m, int n) { int dp[m+1][n+1]; memset(dp, 0, (m+1)*(n+1)*sizeof(int)); for(int i = 0; i <= m; i++) { dp[m][1] = 1; } for(int i = 0; i <= n; i++) { dp[0][n] = 1; dp[1][n] = 1; } for(int i = 1; i <= m; i++) { for(int j = 1; j <= n; j++) { if(i < j) //苹果数量小于盘子数量 { dp[i][j] = dp[i][i]; } else { dp[i][j] = dp[i-j][j] + dp[i][j-1]; } } } return dp[m][n]; } int main() { int m = 0; int n = 0; scanf("%d %d", &m, &n); apple(m, n); return 0; }