#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int f[257],fac[257],ifac[257];
const long long mod = 1e9+7;
int qpow(int x,int y){
int tamp=1;
while(y){
if(y&1)
tamp=1ll*tamp*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return tamp;
}
int combination(int n,int m){
return 1ll*ifac[m]*ifac[n-m]%mod*fac[n]%mod;//n!/(m!*(n-m)!)
}
int main(){
int n,k;
cin>>n>>k;
fac[0]=1;
for(int i=1;i<=n;++i){
f[i]=qpow((qpow(k,i)-qpow(k-1,i)+mod)%mod,n);//f[i]表示有i列格子填上了数字,每一列都有1
//qpow(k,i)表示一列中每一格都用1~k填充,即全排列
//qpow(k-1,i)表示一列中每一格都用2~k填充,即这一列没有1
//相减得到这一列定有1,n次方表示n列每一列都定有1
fac[i]=1ll*fac[i-1]*i%mod;//fac[i]表示sum[1,i](f[i])
}
ifac[n]=qpow(fac[n],mod-2);//费马小定理求逆元
for(int i=n-1;i>=0;--i)
ifac[i]=1ll*ifac[i+1]*(i+1)%mod;//ifac[i]=1/((n!*(n-i)!)/n!)
int ans=0;
for(int i=0;i<=n;++i)
ans=(ans+((i&1)?mod-1ll:1ll)*combination(n,i)%mod*qpow(k-1,1ll*n*i)%mod*f[n-i]%mod)%mod;
//容斥,用全排列的情况减去只有1列没有1加上只有2列没有1减去只有3列没有1加上只有4列没有1......
//多集合取交集容斥问题,公式类似二项式定理即ans=sum[0,n]((-1)^i*(C(n,i)(k-1)^(n*i))*f[n-i])
cout<<ans<<endl;
return 0;
}

Codeforces Round #589 (Div. 2)E(组合数,容斥原理,更高复杂度做法为DP)的更多相关文章

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

    Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...

  2. Codeforces Round #205 (Div. 2)C 选取数列可以选择的数使总数最大——dp

    http://codeforces.com/contest/353/problem/C Codeforces Round #205 (Div. 2)C #include<stdio.h> ...

  3. Codeforces Round 589 (Div. 2) 题解

    Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...

  4. Codeforces Round #589 (Div. 2)

    目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...

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

  6. Codeforces Round #589 (Div. 2) D. Complete Tripartite(染色)

    链接: https://codeforces.com/contest/1228/problem/D 题意: You have a simple undirected graph consisting ...

  7. Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)

    链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...

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

  9. Codeforces Round #589 (Div. 2) A. Distinct Digits

    链接: https://codeforces.com/contest/1228/problem/A 题意: You have two integers l and r. Find an integer ...

随机推荐

  1. PMP概略学习上--基本思想和概念

    1 前言 花了10天左右的时间,对PMP(Project Management Professional,项目管理专业人士)考试认证做了一个概略学习.此次学习的目的是整体了解项目管理知识,并不是以考试 ...

  2. Redis的安装与用法

    Redis的使用方法 ( 命令行安装redis 1  wget http://download.redis.id/releases/redis-5.0.7.tar.gz 2 tar xf redis- ...

  3. CDH安装时,无法纳管全部的节点的一个bug

      问题描述: 使用CDH 5.2版本安装时,agent节点有12个.按照安装说明,在各个节点启动cm-agent之后,发现只有6个节点能被纳管.其它的节点总是无法加入纳管中. 在确认防火墙已经关闭后 ...

  4. fiddler抓包手机准备工作

    1.勾选connections中的:Allow remote computers to connect 2.cmd中查找IP 3.在手机连接的WiFi中设置手动代理为:IP port:8888 4.在 ...

  5. 推荐一个手机端切换地址gps的app

    在写脚本的时候遇到的 客户提供了这个app 免费 自身可以防检测 苹果和安卓都可以使用   官网 http://www.daniu.net/   搜索 大牛 或者danniu即可

  6. CPI和PPI,谁代表了通膨?

    CPI.PPI 一则旧闻,根据 2016年1月9日 统计局公布的数据,CPI同比增长1.6%,PPI同比下降5.9%. Consumer Price Index 缩写CPI,居民消费价格指数. 统计范 ...

  7. java基础(温故而知新)

    一 数据类型 1.1 8种基本数据类型 1.2 引用数据类型 1.3 java内存机制 1.3.1 寄存器 1.3.2 栈 1.3.3 堆 1.3.4. 静态区/方法区 1.3.5. 运行时常量池(R ...

  8. springboot的安装与初步使用

    1.引用springboot框架 1.在maven项目底下的pom.xml的中,引用springboot,如下 <?xml version="1.0" encoding=&q ...

  9. ORACLE_BASE、ORACLE_HOME有什么区别

    ORACLE_BASE.ORACLE_HOME有什么区别   ORACLE_BASE下是admin和productORACLE_HOME下则是ORACLE的命令.连接库.安装助手.listener等等 ...

  10. ARM64架构下面安装mysql5.7.22

    MySQL下载地址为: https://obs.cn-north-4.myhuaweicloud.com/obs-mirror-ftp4/database/mysql-5.7.27-aarch64.t ...