Acwing 1050. 鸣人的影分身
https://www.acwing.com/problem/content/1052/
输入样例:
1
7 3
输出样例:
8
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=200200,M=2020;
LL n,m;
LL ans=0;
void dfs(int idx,int len,int sum)
{
if((m-len)*idx>n-sum) return ;
if(len>=m||sum>=n)
{
if(len==m&&sum==n) ans++;
return ;
}
for(int i=idx;i<=n;i++)
{
if((m-len)*i>n-sum) break ;
dfs(i,len+1,sum+i);
}
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
cin>>T;
while(T--)
{
ans=0;
cin>>n>>m;
for(int i=0;i<=n;i++)
{
dfs(i,1,i);//从i开始,长度为1,总数为i
}
cout<<ans<<endl;
}
return 0;
}