题目链接

问题分析

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

可以枚举没有\(1\)的行数和列数,答案就是

\[\sum\limits_{i=0}^n\sum\limits_{j=0}^m(-1)^{i+j}{n\choose i}{n \choose j}(k-1)^{i*n+j*n-i*j}k^{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的更多相关文章

  1. Another Filling the Grid

    E. Another Filling the Grid 参考:Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 容斥这个东 ...

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

    [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...

  3. Codeforces Round #589 (Div. 2) E. Another Filling the Grid(DP, 组合数学)

    链接: https://codeforces.com/contest/1228/problem/E 题意: You have n×n square grid and an integer k. Put ...

  4. Codeforces Round #589 (Div. 2) B. Filling the Grid

    链接: https://codeforces.com/contest/1228/problem/B 题意: Suppose there is a h×w grid consisting of empt ...

  5. codeforces#1228E. Another Filling the Grid(容斥定理,思维)

    题目链接: https://codeforces.com/contest/1228/problem/E 题意: 给n*n的矩阵填数,使得每行和每列最小值都是1 矩阵中可以填1到$k$的数 数据范围: ...

  6. 【CF589 E】Another Filling the Grid

    一个很套路的容斥裸题,这里记录一下scb 的切题过程 Description 有一个 \(n\times n\) 的矩阵,你需要往每格里填一个 \([1,k]\) 的整数,使得每一行.每一列的最小值都 ...

  7. Codeforces 1228E. Another Filling the Grid

    传送门 看到 $n=250$ 显然考虑 $n^3$ 的 $dp$ 设 $f[i][j]$ 表示填完前 $i$ 行,目前有 $j$ 列的最小值是 $1$ 的合法方案数 那么对于 $f[i][j]$ ,枚 ...

  8. [Codeforces 1228E]Another Filling the Grid(组合数+容斥)

    题目链接 解题思路: 容斥一下好久可以得到式子 \(\sum_{i=0}^{n}\sum_{j=0}^{n}(-1)^{i+j}C_n^iC_n^j(k-1)^{ni+nj-ij}k^{n^2-(ni ...

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

    题意:问有多少种组合方法让每一行每一列最小值都是1 思路:我们可以以行为转移的状态 附加一维限制还有多少列最小值大于1 这样我们就可以不重不漏的按照状态转移 但是复杂度确实不大行(减了两个常数卡过去的 ...

随机推荐

  1. vue之scoped穿透

    vue之scoped穿透 问题:在页面中,需要了第三方插件的样式,又不想取消scoped,防止造成样式污染 方法:>>> 代码: #tab >>> .ivu-tab ...

  2. Dreamweaver CS6 破解安装

    安装 双击Dreamweaver.dmg文件,然后Command+N,新建一个Finder,接着将Adobe Dreamweaver CS6拖到新建Finder的应用程序中.   在Finder中应用 ...

  3. Tomcat面试题汇总

    详见:Tomcat 面试题汇总:https://blog.csdn.net/qq_25934401/article/details/81536958 1.Tomcat的缺省端口是多少,怎么修改? to ...

  4. Spring特点与工作原理

    根据多个参考资料,总结如下: Spring的概念 Spring是一种多层的J2EE应用程序框架,其核心就是提供一种新的机制管理业务对象及其依赖关系.它是一种容器框架,用于创建bean,维护bean之间 ...

  5. 如何判断kbmMWClientQuery当前记录的增改状态?

    有朋友问我,客户端使用了kbmMWClientQuery,对其进行了编辑后,对于指定的记录,如何判断是否是增加的记录,或者是被修改后的记录? 下面这个函数,返回aDataSet当前记录的修改状态: f ...

  6. Python单元测试框架unittest重要属性 与 用例编写思路

    前言 本文为转载,原文地址作者列举python unittest这个测试框架的主要属性和 测试用例思路 unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行, ...

  7. kubernetes资源清单之Deployment

    Deployment为Pod和ReplicaSets提供声明性更新 示例 --- apiVersion: apps/v1 kind: Deployment metadata:     name: de ...

  8. (九)全志平台Tina系统量产前adb shell设密码的方法

    全志平台Tina系统量产前adb shell设密码的方法[适用范围] 全志平台Tina系统 [问题现象] 通常产品量产后都想要以安全方式封闭adb shell,不允许用户或其他开发者使用,因此需要以安 ...

  9. servlel出现404问题★ 出现不自动映射 设置XML的问题时候

    ★ 出现不自动映射 设置XML的问题时候 可能是 web.xml配置可能是复制的  错误原因来自于name的匹配 <display-name>webdemo1</display-na ...

  10. Linux使用storcli工具查看服务器硬盘和raid组信息

    1.简介 MegaCli 是LSI公司官方提供的SCSI卡管理工具,由于LSI被收购变成了现在的Broadcom,所以现在想下载MegaCli, 需要去Broadcom官网查找Legacy产品支持,搜 ...