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 =:
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
represents a specific
row had been coated,
column is not painted,
color scheme useless number. Clear
then
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;
}