题解 | #放苹果#
放苹果
https://www.nowcoder.com/practice/4f0c1e21010e4d849bde5297148e81d9
#include<iostream> using namespace std; int m,n; int dfs(int u,int sum,int last) { if(u == n){ if(sum == 0) return 1; else return 0; } int res = 0; for(int i = last;i <= sum;i++) { res += dfs(u + 1,sum - i,i); } return res; } int main(void) { cin >> m >> n; cout << dfs(0,m,0) << endl; return 0; }