CF1228E Another Filling the Grid

Posted chy-2003

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF1228E Another Filling the Grid相关的知识,希望对你有一定的参考价值。

题目链接

问题分析

比较显见的容斥,新颖之处在于需要把横竖一起考虑……

可以枚举没有\(1\)的行数和列数,答案就是
\[ \sum\limits_i=0^n\sum\limits_j=0^m(-1)^i+jn\choose in \choose j(k-1)^i*n+j*n-i*jk^n*n-i*n-j*n+i*j \]
个数算对就好了……

参考程序

#include <bits/stdc++.h>
#define LL long long
using namespace std;
 
const LL Mod = 1000000007;
const LL Maxn = 260;
LL n, k;
LL Fact[ Maxn ], INV[ Maxn ];
 
LL Pow( LL x, LL y ) 
    LL Ans = 1;
    for( ; y; y >>= 1, x = x * x % Mod )
        if( y & 1 )
            Ans = Ans * x % Mod;
    return Ans;

 
LL C( LL n, LL m ) 
    return Fact[ n ] * INV[ m ] % Mod * INV[ n - m ] % Mod;

 
int main() 
    Fact[ 0 ] = 1;
    for( LL i = 1; i < Maxn; ++i ) Fact[ i ] = Fact[ i - 1 ] * i % Mod;
    INV[ Maxn - 1 ] = Pow( Fact[ Maxn - 1 ], Mod - 2 );
    for( LL i = Maxn - 2; i >= 0; --i ) INV[ i ] = INV[ i + 1 ] * ( i + 1 ) % Mod;
 
    scanf( "%lld%lld", &n, &k );
    LL Ans = 0;
    for( LL i = 0; i <= n; ++i )
        for( LL j = 0; j <= n; ++j ) 
            LL Num = ( i + j ) * n - i * j;
            LL t1 = C( n, i ) * C( n, j ) % Mod;
            LL Method = t1 * Pow( k - 1, Num ) % Mod * Pow( k, n * n - Num ) % Mod;
            if( ( i + j ) % 2 == 0 ) Ans = ( Ans + Method ) % Mod; 
            else Ans = ( Ans + Mod - Method ) % Mod;
        
    printf( "%lld\n", Ans );
    return 0;

以上是关于CF1228E Another Filling the Grid的主要内容,如果未能解决你的问题,请参考以下文章

[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)

Another Filling the Grid

E. Another Filling the Grid 状压dp

Codeforces 1228E. Another Filling the Grid

Codeforces Round #589 (Div. 2) Another Filling the Grid (dp)

Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理