Division of numbers
Topic link: division of numbers
Title description
Problem solving ideas
设 f i , j f_{
{i},{j}} fi,jHe said it would iii is divided intojjNumber of cases of j copies.
Obviously, wheni = ji=ji=j 时 f ( i ) ( j ) f(i)(j) There is only one case for f ( i ) ( j ) , which is1 11 .
Ifj> i j>ij>i , even1 11 is not enough, so it must be illegal, as0 00 .
Consider the normal situation:
- If we add 1 1 after the original sequence1 , then the original total isi − 1 i-1i−1 , the original number of copies isj − 1 j-1j−1。
- If we add 1 1 to each number on the basis of the original sequence1 , then the original total isi − j iji−j , the original number of copies isjjj。
Then the recurrence formula is:
fi, j = fi − 1, j − 1 + fi − j, j f_{
{i},{j}}=f_{
{i-1},{j-1}}+f_ {
{ij},{j}}fi,j=fi−1,j−1+fi−j,j
code
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int f[210][10];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(i==j)
f[i][j]=1;
else if(j>i)
f[i][j]=0;
else
f[i][j]=f[i-1][j-1]+f[i-j][j];
}
cout<<f[n][m];
}