https://ac.nowcoder.com/acm/problem/16695
#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,k;
LL ans=0;
void dfs(int idx,int len,int sum)
{
if((k-len)*idx>n-sum) return ;
if(len>=k||sum>=n)
{
if(len==k&&sum==n) ans++;
return ;
}
for(int i=idx;i<=n;i++)
{
if((k-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--)
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
if(k*i>n) break;
dfs(i,1,i);//从i开始,长度为i,总数为i
}
cout<<ans<<endl;
}
return 0;
}
标签:NOIP2001,idx,int,sum,len,牛客,划分,dfs,LL
From: https://www.cnblogs.com/Vivian-0918/p/18103990