- The number of division (% MOD) requirements of $ A_n ^ m $. There recurrence equation: $ dp [i] [j] = \ sum_ {k = 0} ^ {j} dp [i-1] [jk] $, where $ dp [i] [j] $ to $ $ J the total number of $ i $ divided.
- The number of division (% MOD) required $ C_n ^ m $, there is recurrence equation: $ dp [i] [j ] = dp [i] [j-1] + dp [i-1] [j] $.
code show as below:
1 int n, m; 2 int dp[MAX_M + 1][MAX_N + 1]; // DP数组 3 4 int solve() { 5 dp[0][0] = 1; 6 for (int i = 1; i <= m; i++) { 7 for (int j = 0; j <= n; j++) { 8 if (j - i >= 0) { 9 dp[i][j] = (dp[i - 1][j] + dp[i][j - i]) % MOD; 10 } else { 11 dp[i][j] = dp[i - 1][j]; 12 } 13 } 14 } 15 return dp[m][n]; 16 }
- Multiple sets the number of combinations, there are n items, there are i-th $ a $ a_i. Different types of items can be distinguished from each other but can not distinguish the same species. From these items of m number of species in a borrowing.
Recurrence equation: $ dp [i + 1] [j] = dp [i + 1] [j-1] + dp [i] [j] -dp [i] [j-1-a_i] $
code is as follows:
. 1 int n-, m; 2 int A [MAX_N]; . 3 int DP [MAX_N + . 1 ] [M + + mAX . 1 ]; . 4 . 5 int Solve ({) . 6 // method does not always take only one . 7 for ( int I = 0 ; I <= n-; I ++ ) { . 8 DP [I] [ 0 ] = . 1 ; . 9 } 10 for ( int I = 0 ; I <n-; I ++ ) { . 11 for ( int J =1; j <= m; j++) { 12 if (j - 1 - a[i] >= 0) { 13 dp[i + 1][j] = 14 (dp[i + 1][j - 1] + dp[i][j] - dp[i][j - 1 - a[i]] + MOD) % 15 MOD; 16 } else { 17 dp[i + 1][j] = (dp[i + 1][j - 1] + dp[i][j]) % MOD; 18 } 19 } 20 } 21 return dp[n][m]; 22 }
The number of combinations related to the number of combinations of multiple sets
Guess you like
Origin www.cnblogs.com/romaLzhih/p/11415506.html
Recommended
Ranking