Portal: Https://i.cnblogs.com/EditPosts.aspx?opt=1
Problem Solving Ideas:
M: Number of apples, N: Number of plates.
F (m,n): Number of =m apples on n plates
1.n>m
There will always be n-m a plate left, then the problem can be converted to F (m,m)
2. N<=m
At this time there are two cases, each plate is put, and then put m-n an apple into N plate f (m-n,n);
At least one plate is not put, then put M apples into n-1 plate f (m,n-1);
Basic situation
Only 1 apples, or 0 apples, only one case.
There is only one case when there is only a plate.
Implementation code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 7 //m apples, n plates8 intSolveintMintN) {9 if(n==1|| m==1|| m==0)Ten return 1; One if(n>m) A returnsolve (m,m); - Else - returnSolve (m,n-1) +solve (M-n,n); the } - - intMain () { - intT; +scanf"%d",&T); - while(t--){ + intn,m; Ascanf"%d%d",&m,&n); atCout<<solve (m,n) <<Endl; - } -}
POJ 1664 putting apples