[Ybtoj high-efficiency advanced 1.1] [recursion] division of numbers

[Ybtoj high-efficiency advanced 1.1] [recursion] division of numbers

topic

Insert picture description here


Problem-solving ideas

Let f[i][j] divide the integer i into j points
. Obviously when i==j, f[i][j] is 1
and i<j when f[i][j]=0

  • At least one part is 1, indicating that i-1 is divided into j-1 points, and another 1 is added as one part, and the number of plans is f[i-1][j-1]
  • Each part is greater than 1, first give each part 1, and then divide the rest into j parts and add them separately, the number of plans is f[ij][j]

Code

#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
long long f[220][220];
int main()
{
    
    
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	    f[i][i]=1;
	for (int i=2;i<=n;i++)
	    for (int j=1;j<i;j++)
	           f[i][j]=f[i-1][j-1]+f[i-j][j];
	printf("%lld\n",f[n][m]);
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_45621109/article/details/111640223