问题在于dfs序列是递增的,所以要记录一下最大值
#include<iostream>
#include<vector>
using namespace std;
long long M,N;
long long count;
void dfs(int nowm,int nown,int next)
{
if(nown==N)
{
if(nowm==0)
count++;
return;
}
for(int i=next;i<=nowm;i++)
{
dfs(nowm-i,nown+1,i);
}
}
int main()
{
long long l;
cin>>l;
while(l--)
{
cin>>M>>N;
count=0;
dfs(M,0,0);
cout<<count<<endl;
}
return 0;
}