4487: [Jsoi2015] staining issue time limit:10 Sec Memory limit:512 MB
submit:211 solved:127
[Submit] [Status] [Discuss] Description
The chessboard is a nxm rectangle, divided into n rows m column n*m a small square. Now Moe and South-South have c colors of different pigments, they want to dye the board with these pigments, and meet the following provisions:
1. Every small square of the chessboard can be dyed (one of the colors of C) or not.
2. At least one small square in each line of the chessboard is dyed.
3. At least one of the squares in each column of the chessboard is dyed.
4. All colors appear at least once on the board.
Here are some examples of coloring a 3x3 checkerboard into C = 3 colors (red, yellow, blue):
Please find out the total number of different staining schemes that meet the requirements. As long as there is a different color in a position,
That the two staining schemes are different Input
Enter only one line of 3 integers n,m,c. 1 < = N,m,c < = Output
Outputs an integer that is the total number of different staining schemes. Because the total may be large, just the total output
The value of MoD 1,000,000,007. Sample Input
2 2 3 Sample Output
HINT Source
From one-dimensional tolerance to three-dimensional repulsion.
Very weird, not very understanding, perceptual
Enumeration Ijk, indicating that I row J columns occupy K color or do not paint any selected
Let it go.
The formula is O (n^3), which can be optimized to O (n^2*log2 (M)) according to the two-term theorem
Watch Blog
http://blog.csdn.net/nirobc/article/details/51064832
#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>#defineN 403#defineP 1000000007#defineLL Long Longusing namespacestd;intN,m,c; LL C[n][n]; LL Quickpow (intNumintx) {LL ans=1,Base=num; while(x) {if(x&1) ans=ans*Base%p; X>>=1; Base=Base*Base%Q; } returnans;}intMain () {scanf ("%d%d%d",&n,&m,&c); for(intI=0; i<= -; i++) c[i][0]=1; for(intI=1; i<= -; i++) for(intj=1; j<=i;j++) C[i][j]= (c[i-1][j]+c[i-1][j-1])%p; LL ans=0; for(intk=0; k<=c;k++) {LL x=1; for(inti=n;i>=0; i--) {LL tot=1; for(intj=m;j>=0; j--) { intt=i+j+K; LL Now=c[n][i]*c[m][j]%p*c[c][k]%p*tot%p; if(t&1) ans-=Now ; Elseans+=Now ; Tot=tot*x%p; } x=x* (c-k+1)%p; Ans%=p; }} printf ("%lld\n", (ans%p+p)%p);}
4487[JSOI2015] staining problem tolerance + combination