E. Another Filling the Grid

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

容斥这个东西可以理解,但是运用到实际的时候,还是觉得有点迷迷糊糊的,不知道套公式会不会是一种可行的办法。

是时候也得把以前的知识温习一下了....

具体的思路看参考的博客就可以理解了。

代码:

// Created by CAD on 2019/10/2.
#include <bits/stdc++.h>
#define ll long long
using namespace std; const int mod=1e9+7;
ll qpow(ll x,ll n)
{
ll re=1;
while(n)
{
if(n&1) re=(re*x)%mod;
n>>=1,x=(x*x)%mod;
}
return re;
}
ll c[300][300];
int main()
{
ll n,k; cin>>n>>k;
for(int i=0;i<=250;++i)
{
c[i][0]=c[i][i]=1;
for(int j=1;j<i;++j)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
ll ans=0;
for(int i=0;i<=n;++i)
for(int j=0;j<=n;++j)
{
ans=(ans+((i+j)&1?-1:1)*c[n][i]%mod*c[n][j]%mod*
qpow(k-1,n*(i+j)-i*j)%mod*qpow(k,n*n-n*(i+j)+i*j)%mod+mod)%mod;
}
cout<<ans<<endl;
}

Another Filling the Grid的更多相关文章

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

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

  2. 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 ...

  3. 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 ...

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

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

  5. 【CF589 E】Another Filling the Grid

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

  6. Codeforces 1228E. Another Filling the Grid

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

  7. CF1228E Another Filling the Grid

    题目链接 问题分析 比较显见的容斥,新颖之处在于需要把横竖一起考虑-- 可以枚举没有\(1\)的行数和列数,答案就是 \[ \sum\limits_{i=0}^n\sum\limits_{j=0}^m ...

  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. Java New IO

    1.NIO介绍 应用程序中,通常会涉及两种类型的计算:计算密集型和I/O密集型.对多数应用来说,花费在等待IO上的时间是比较大的.因此提高IO操作效率对应用的性能至关重要. 面向流的IO系统一次处理一 ...

  2. .Net面试题二

    谈谈创建线程的方式 1.列举.Net页面之间传值的方式 2..Net中aspx页面从客户端浏览器开始请求到服务器返回响应所经历的过程 CLR主要运行过程 ASP.NET运行管道所有事件 3.如何理解委 ...

  3. ef core schema 指定架构

    不知道很少使用Schema模型还是怎么,居然搜帖子没人说,虽然很简单但是还是想记录一下坑 命名空间 using System.ComponentModel.DataAnnotations.Schema ...

  4. golang(8):channel读写 & goroutine 通信

    goroutine 1.进程和线程 A. 进程是程序在操作系统中的一次执行过程,系统进行资源分配和调度的一个独立单位 B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独 ...

  5. 非常有用的pointer-events属性

    介绍 pointer-events是css3的一个属性,指定在什么情况下元素可以成为鼠标事件的target(包括鼠标的样式) 属性值 pointer-events属性有很多值,但是对于浏览器来说,只有 ...

  6. JS基础_打印出1-100之间所有的质数

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. pthread 笔记

    1.创建线程 res = pthread_create(&a_thread, NULL, thread_function1, NULL); if (res != 0) { perror(&qu ...

  8. LintCode 547---两数组的交集

    public class Solution { /** * 给出两个数组,写出一个方法求出它们的交集 * @param nums1: an integer array * @param nums2: ...

  9. nfs服务器的搭建和使用

    目录 更新记录 1.nfs介绍 1.1 nfs概念 1.2 nfs工作原理 1.3 nfs通讯过程 2.搭建和测试 NFS 服务器 2.1 搭建NFS服务器 2.2 测试NFS服务器 3.在线调试:N ...

  10. promise使用的正确方式

    一开始恨不能理解下面的代码,为什么可以一直then下去,什么时候要直接return  xxx,什么时候return 一个promise,什么时候用Promise.resolve() function ...