Division of numbers
Title description
Divide integers into components, and each portion cannot be empty. Any two solutions are different (regardless of order).
For example: The following three classifications are considered the same:
1,1,5; 1,5,1; 1,1,5.
Ask how many different divisions are there.
Input format
Two integers, and.
Output format
Output different division numbers.
Sample
Input sample
7 3
Output sample
4
Sample explanation
Four classification methods are: 1,1,5; 1,2,4; 1,3,3; 2,2,3.
Data range and tips
For 100% of data, 6≤n≤200, 2≤k≤6.
Problem solving ideas
Let f(i,j) be the
initial value of the number of schemes divided by i into j :
when j=1 and i=j , f(i,j)=1
Recursion:
two cases
1. At least one of j shares is 1, and the number of plans is f(i-1, j-1)
2. There is no 1 in j shares, consider dividing ij into j shares, and then go to each of j shares Copies +1, the number of plans is f(ij,j)
Late reasoning formula:
f (i, j) = f (i − 1, j − 1) + f (i − j, j) f (i, j) = f (i-1, j-1) + f (ij, j)f(i,j)=f(i−1,j−1)+f(i−j,j)
AC code
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,f[205][10];
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
for(int j=1;j<=min(i,k);j++)
if(j==1||i==j)f[i][j]=1;//初值
else f[i][j]=f[i-j][j]+f[i-1][j-1];//递归
printf("%d",f[n][k]);
return 0;
}