Ultraviolet A 11806-Cheerleaders (rejection principle + binary)
Question:
Place k stones in a grid of n rows and m columns. How many methods are there? The first, first, last, and last columns must contain stones.
Ideas:
1. Expansion of the principle of rejection
Assume that there are three sets, S, and three other sets, a B c, do not belong to A, B, C, any set, but belong to the elements of the complete set, odd subtraction; even Addition
Here, S is an empty Set A, B, C, and D, respectively, representing four situations in the row column:
AUBUCUD = | A | + | B | + | C | + | D |-| AB |-| BC |-| AC |-| AD |-| BD |-| CD | + | ABC | + | ABD | + | ACD | + | BCD |-| ABCD |
If A or B is in the Set, A row is missing; if C or D is in the Set, A column is missing.
Assuming that the row and col columns are left at the end, the number of methods is C (row * col, k ).
2. binary representation of the combination of four conditions
3. Calculate the number of combinations: C (n + 1, k + 1) = c (n, k + 1) + (n, k)
# Include
# Include
# Include
# Include
# Define deusing namespace std; typedef long LL; # define MOD 1000007 # define MAX 510int c [MAX] [MAX]; void C () // calculate the number of combinations {memset (c, 0, sizeof (c); c [0] [0] = 1; for (int I = 0; I <= 500; I ++) {c [I] [0] = c [I] [I] = 1; for (int j = 1; j