http://noi.openjudge.cn/ch0203/666/
"""
2.3 基本算法之递归变递推 666 放苹果
http://noi.openjudge.cn/ch0203/666/
C和Python实现放苹果
https://zhuanlan.zhihu.com/p/340794311
Python如何实现佩尔数列?
https://www.zhihu.com/question/495732022/answer/2200069561
"""
def putInPlate(m, n):
if(m== 1 or m==0 or n==1):
return 1
if(m <0):
return 0
return putInPlate(m-n,n)+putInPlate(m,n-1)
t=int(input())
a = 0
while a< t:
m,n= map(int, input().split())
if(n==0):
break;
print(putInPlate(m,n))
a += 1
参考:
C和Python实现放苹果
https://zhuanlan.zhihu.com/p/340794311
Python如何实现佩尔数列?
https://www.zhihu.com/question/495732022/answer/2200069561
C++代码:
/*
2.3基本算法之递归变递推_666放苹果
http://noi.openjudge.cn/ch0203/666/
1192:放苹果
http://ybt.ssoier.cn:8088/problem_show.php?pid=1192
*/
#include<iostream>
#include<cstring>
using namespace std;
int a[20][20];
int f(int m,int n)
{
int i,j;
for(i=1;i<=n;i++)//0个苹果
a[0][i]=1;
for(i=1;i<=m;i++)//1个盘子
a[i][1]=1;
for(i=1;i<=m;i++)
for(j=2;j<=n;j++)
if(i<j)
a[i][j]=a[i][i];
else
a[i][j]=a[i][j-1]+a[i-j][j];
}
int main()
{
int m,n,i,j,k;
cin>>k;
for(i=1;i<=k;i++)
{
cin>>m>>n;
f(m,n);
cout<<a[m][n]<<endl;
}
return 0;
}