跳到正文

个人记录

P1025放苹果

lzz131113约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年2月24日
更新
2026年2月24日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1
C++
#include <bits/stdc++.h>
using namespace std;
int n,k,sum=0,a[201];
void dfs(int b)
{
	if (n==0)
	{
		return;
	}
	if (b==k)
	{
		if (n>=a[b-1])
		{
			sum++;
		}
		return ;
	}
	for (int i=a[b-1];i<=n/(k-b+1);i++)//c
	{
		a[b]=i;
		n-=i;
		dfs(b+1);
		n+=i;
	}
}
int main()
{
	cin>>n>>k;
	a[0]=1;
	dfs(1);
	cout <<sum;
	return 0;
}
原文