[Ybt] [Basic calculation recurrence lesson example 3] Division of numbers

Division of numbers

Topic link: division of numbers


Title description

Insert picture description here
Insert picture description here

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-1i1 , the original number of copies isj − 1 j-1j1
  • If we add 1 1 to each number on the basis of the original sequence1 , then the original total isi − j ijij , 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=fi1,j1+fij,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];
}

Guess you like

Origin blog.csdn.net/SSL_guyixin/article/details/111641743