Permutation and combination is a branch of mathematics. It also has many applications in computer programming, including arrangement formulas and combination formulas, incorrect arrangement formulas, primary functions, and catalan number.
1. Formulas for combined mathematics
1. arrangement formula P (n, R) = n! /R!
2. Combination formula C (n, R) = n! /(R! * (N-R )!) C (n, R) = C (n-1, R) + C (n-1, R-1)
3. formula D [1] = 0; d [2] = 1;
D [N] = (n-1) * (d [n-1] + d [N-2])
4. catlands
First few items: 1, 2, 5, 14, 42,132,429,143 0, 4862,167 96, 58786, 208012...
Formula C (n) = C (2n, N)/(n + 1)
5. Primary Functions
In mathematics
Primary function Is a form of idempotent series. The coefficients of each item can provide information about this sequence. The method for solving the problem using the primary function is called
Primary Function Method . There are many types of functions, including
Common functions ,
Exponential functions ,
L series ,
Bell Series And
Dirichlet Series . You can write a primary function of each of the above types for each sequence. The purpose of constructing a primary function is generally to solve a specific problem. Therefore, the type of primary function depends on the characteristics of the sequence and the type of the problem. (Baidu encyclopedia) Mother function template (for decomposition of N ):
/******************************题目大意:求分解整数n的个数q(n)例:5 = 5;5 = 4 + 1;5 = 3 + 1 + 1;5 = 3 + 2;5 = 2 + 2 + 1;5 = 2 + 1 + 1 + 1;5 = 1 + 1 + 1 + 1 + 1;sum(5) = 7;不区分顺序,(3+2)与(2+3)为同一个*******************************/
int main(){ int a[350],b[350],i,j,k,n; while(cin>>n&&n) { for(i=0;i<=n;i++){ a[i]=1; b[i]=0; } for(i=2;i<=n;i++){ for(j=0;j<=n;j++) for(k=0;k+j<=n;k+=i) b[k+j]+=a[j]; for(j=0;j<=n;j++){ a[j]=b[j]; b[j]=0; } } cout<<a[n]<<endl; } return 0;}
II,STLFull Permutation function in
Function declaration: # include <algorithm>
Bool next_permutation (iterator start, iterator end );
Next_permutation () The function is used to output all the orders that are larger than the current order.
Prev_permutation ()The function is to output all the smaller orders than the current one. The order is from large to small.
3. self-defined fully-arranged Functions
Void range (int A [], int K, int N ){
If (k = N ){
For (INT I = 1; I <= N; I ++ ){
Printf ("% d", a [I]);
}
Printf ("\ n ");
}
For (INT I = K; I <= N; I ++ ){
Swap (A [K], a [I]);
Range (A, K + 1, n );
Swap (A [K], a [I]);
}
}
Iv. Examples of HDU questions
Question 1: hdu1027 gives n, m, and calculates the m sequence of n numbers in Lexicographic Order.
Question 2: hdu1028 calculate the number of decomposition of a positive integer n
Question 3: hdu1171 provides the value and number of items, which are divided into two parts, which is the minimum difference between the two parts.
Question 4. hdu1261: Given several letters and their corresponding numbers, calculate the number of different characters that can be composed (High Precision)
Question 5 and hdu1398 give a number N, and use the given sequence to find all types of N.
Question 6: application of the hdu1465 error row formula
Question 7: hdu1492 calculate the approximate number of all Humber bunber of a number
Question 8: Application of hdu1570 arrangement and combination Formula
Question 9 and hdu1716 have four cards, which can be used to list many different 4-digit numbers and output these 4-digit numbers in ascending order.
Question 10. Use the recursive formula to calculate the number of combinations in hdu1799
Question 11,Hdu1085Returns the numbers 1, 2, and 5 to find the minimum discontinuous value.
ACM ~ Arrangement and Combination & HDU example