bzoj 4487 / jsoi 2015 coloring problem (inclusion and exclusion

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/iamhpp/article/details/100806424

Description

The board is a rectangular n × m, is divided into a total of n rows and m columns * n m smaller squares.
Meng Meng and South-South C now have different colors of pigment, they want to board with these pigment dyeing and meet the following requirements:
1. The board of every little squares either stained (dyed in one color in C ), may not be stained.
2. Each row of the board have at least a small square stained.
3. The board of each column there is at least a small square stained.
4. colors appear at least once on the board.
The following are some examples of three colors (red, yellow, blue) of the 3 × 3 checkerboard dyed C =:
Here Insert Picture Description

You different solutions to meet the requirements of the total number of staining obtained. As long as there is a position of a different color,
that is considered to be two different staining protocols

Input

3 only one line input integer n, m, c. 1 <= n, m, c <= 400

Output

Output an integer, the total number of different staining protocols.
Because the total number may be large, just mod the total output value of 1,000,000,007.

Sample Input

2 2 3

Sample Output

60

analysis

This question has three restrictions: each line to be painted, each column to be painted on each color to use. Consider its opposite: there are no painted lines, there are no columns painted, color is useless, use this to inclusion and exclusion. Remember f ( i , j , k ) f(i,j,k) represents a specific i i row had been coated, j j column is not painted, k k color scheme useless number. Clear f ( i , j , k ) = ( c k ) ( n i ) ( m j ) f(i,j,k) = (c - k)^{(n-i)*(m-j)}
then a n s = i = 0 n j = 0 n k = 0 c ( 1 ) i + j + k C n i C m j C c k f ( i , j , k ) = i = 0 n j = 0 n k = 0 c ( 1 ) i + j + k C n i C m j C c k ( c k ) ( n i ) ( m j ) ans = \sum\limits_{i=0}^{n}\sum\limits_{j=0}^{n}\sum\limits_{k=0}^{c}(-1)^{i+j+k}C_n^iC_m^jC_c^kf(i,j,k)\\=\sum\limits_{i=0}^{n}\sum\limits_{j=0}^{n}\sum\limits_{k=0}^{c}(-1)^{i+j+k}C_n^iC_m^jC_c^k(c - k)^{(n-i)*(m-j)}

code show as below

#include <bits/stdc++.h>
#define mod 1000000007
#define LL long long
using namespace std;
int c[405][405], P[160005];
LL z = 1, ans;
int ksm(int a, int b, int p){
	int s = 1;
	if(!a) return 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
int main(){
	int i, j, n, m, k, t;
	for(i = 0; i <= 400; i++){
		c[i][0] = 1;
		for(j = 1; j <= i; j++) c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;
	}
	scanf("%d%d%d", &n, &m, &k);
	for(t = 0; t <= k; t++){
		for(P[0] = i = 1; i <= n * m; i++) P[i] = z * P[i-1] * (k - t + 1) % mod;
		for(i = 0; i <= n; i++){
			for(j = 0; j <= m; j++){
				if((i + j + t) % 2) ans = (ans - z * c[n][i] * c[m][j] % mod * c[k][t] % mod * P[(n - i) * (m - j)]) % mod;
				else ans = (ans + z * c[n][i] * c[m][j] % mod * c[k][t] % mod * P[(n - i) * (m - j)]) % mod;
				
			}
		}
	}
	printf("%lld", (ans % mod + mod) % mod);
	return 0;
}

Guess you like

Origin blog.csdn.net/iamhpp/article/details/100806424