[BZOJ3294] put chess pieces (dynamic planning, tolerance and exclusion, Combinatorial Mathematics)

Problem surface

Luo Gu

Title Solution

If a row or a column is occupied by a certain color, you can directly discard these rows and columns when considering other rows.
So we can write a dpdp
Let f[i][r][c]f[i][r][c] indicate that the first two colors are considered, and the remaining rr row cc column is not stained.
So when transferring, enumerate the current color stained aa row bb column transfer.
But the problem is, how to calculate the number of schemes that use KK pieces to cover aa rows and bb columns?
It's just not easy to calculate. Let's change it to cover at most the number of schemes in row aa and column bb.
So it's easy to figure out this is CKabCabK.
Then we can calculate the number of schemes that exactly cover row aa and column bb.
When we calculate a, Ba and B, we can calculate the number of schemes that cover L, l < Al, l < a row, R < BR, R < B column,
Then just subtract the illegal from the total.
Next is a very simple dpdp. Just use the combination number a little.

using namespace std;
#define ll long long
#define MOD 1000000009
#define MAX 35
inline int read()
    int x=0;bool t=false;char ch=getchar();
    return t?-x:x;
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
int n,m,c,ans;
int f[MAX][MAX][MAX],a[MAX];
int jc[MAX*MAX],jv[MAX*MAX],inv[MAX*MAX];
int g[MAX][MAX][MAX];
int C(int n,int m){if(m>n)return 0;return 1ll*jc[n]*jv[m]%MOD*jv[n-m]%MOD;}
int main()
    for(int i=1;i<=c;++i)a[i]=read();
    for(int i=1;i<=n*m;++i)jc[i]=1ll*jc[i-1]*i%MOD;
    for(int i=2;i<=n*m;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
    for(int i=1;i<=n*m;++i)jv[i]=1ll*jv[i-1]*inv[i]%MOD;
    for(int i=1;i<=c;++i)
        for(int j=1;j<=n;++j)
            for(int k=1;k<=m;++k)
                for(int l=1;l<=j;++l)
                    for(int r=1;r<=k;++r)
    for(int i=1;i<=c;++i)
        for(int j=1;j<=n;++j)
            for(int k=1;k<=m;++k)
                for(int a=1;a<=j;++a)
                    for(int b=1;b<=k;++b)
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)add(ans,f[c][i][j]);
    return 0;

Posted on Fri, 10 Jan 2020 11:35:08 -0500 by SouThPaw09