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