传送门:http://codeforces.com/problemset/problem/997/C

【题解】

注意在把$i=0$或$j=0$分开考虑的时候,3上面的指数应该是$n(n-j)+j$

至少一行一列相同颜色,那么这些相同颜色的行列一定是同一种颜色,所以是$3^((n-i)(n-j)+1)$。

如果只有若干行相同颜色,那么这些相同颜色的行之间的颜色不一定相同,所以是$3^((n-j)j+j)$。

# include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int mod = ;
const int M = 1e6 + ; int n, fac[M], inv[M]; inline int pwr(int a, int b) {
int ret = ;
while(b) {
if(b&) ret = 1ll * ret * a % mod;
a = 1ll * a * a % mod;
b >>= ;
}
return ret;
} inline int C(int n, int m) {
return 1ll * fac[n] * inv[m] % mod * inv[n-m] % mod;
} int main() {
cin >> n;
fac[] = ; inv[] = ;
for (int i=; i<=n; ++i) fac[i] = 1ll * fac[i-] * i % mod;
inv[n] = pwr(fac[n], mod-);
for (int i=n-; i>=; --i) inv[i] = 1ll * inv[i+] * (i+) % mod;
int A = , B = ;
for (int j=; j<=n; ++j) {
int tem = 1ll * C(n, j) * pwr(, (1ll * n * (n-j) + j) % (mod-)) % mod;
if(j&) B += tem;
else B -= tem;
if(B >= mod) B -= mod;
if(B < ) B += mod;
}
B <<= ;
if(B >= mod) B -= mod; int q = ;
for (int i=; i<n; ++i) {
int t = pwr(-q+mod+, n) - pwr(-q+mod, n);
if(t < ) t += mod;
if(i&) A = A + 1ll * C(n, i) * t % mod;
else A = A - 1ll * C(n, i) * t % mod;
if(A >= mod) A -= mod;
if(A < ) A += mod;
q = 3ll * q % mod;
}
A = 3ll * A % mod;
int ans = A+B;
if(ans >= mod) ans -= mod;
cout << ans; return ;
}

codeforces997C Sky full of stars的更多相关文章

  1. Codeforces997C Sky Full of Stars 【FMT】【组合数】

    题目大意: 一个$n*n$的格子,每个格子由你填色,有三种允许填色的方法,问有一行或者一列相同的方案数. 题目分析: 标题的FMT是我吓人用的. 一行或一列的问题不好解决,转成它的反面,没有一行和一列 ...

  2. CF997C Sky Full of Stars

    CF997C Sky Full of Stars 计数好题 在Ta的博客查看 容斥式子:发现只要每个钦定方案的贡献都考虑到再配上容斥系数就是对的 O(n^2)->O(n) 把麻烦的i=0,j=0 ...

  3. codeforces 997C.Sky Full of Stars

    题目链接:codeforces 997C.Sky Full of Stars 一道很简单(?)的推式子题 直接求显然不现实,我们考虑容斥 记\(f(i,j)\)为该方阵中至少有\(i\)行和\(j\) ...

  4. Codeforces 997 C - Sky Full of Stars

    C - Sky Full of Stars 思路: 容斥原理 题解:http://codeforces.com/blog/entry/60357 注意当i > 1 且 j > 1,是同一种 ...

  5. 【题解】CF997C Sky Full of Stars

    [题解]CF997C Sky Full of Stars 为什么我的容斥原理入门题是这道题????????? \(Part-1\)正向考虑 直接考虑不合法合法的方案吧 所以我们设行有\(i\),列有\ ...

  6. [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)

    [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...

  7. cf997C. Sky Full of Stars(组合数 容斥)

    题意 题目链接 \(n \times n\)的网格,用三种颜色染色,问最后有一行/一列全都为同一种颜色的方案数 Sol Orz fjzzq 最后答案是这个 \[3^{n^2} - (3^n - 3)^ ...

  8. CF997C Sky Full of Stars 数论

    正解:容斥 解题报告: 传送门! 两个方法,分别港下QAQ 先说第一种 首先要推出式子,就∑2*C(i,n)*(-1)i+1*3i*3n*n-n+3*∑∑(-1)i+j+1*C(i,n)*C(j,n) ...

  9. Codeforces.997C.Sky Full of Stars(容斥 计数)

    题目链接 那场完整的Div2(Div1 ABC)在这儿.. \(Description\) 给定\(n(n\leq 10^6)\),用三种颜色染有\(n\times n\)个格子的矩形,求至少有一行或 ...

随机推荐

  1. 使用JavascriptExecutor改变页面元素

    如下如html的页面代码 <html> <body> <input type="text" name="text" value=& ...

  2. Cannot open the disk 'D:\win7-ie8\Windows 7 x64.vmdk' or one of the snapshot

    使用机子过程中断电,开机后使用虚拟机提示[Cannot open the disk 'D:\win7-ie8\Windows 7 x64.vmdk' or one of the snapshot],找 ...

  3. shell 指令 摘录

    作者: learner811    本文摘自网络    权限:用户 读写 ugoa rwx * useradd userdel groupadd groupmod usermod su sudo wh ...

  4. JS贪吃蛇小游戏

    效果图展示: 具体实现代码如下: (1)html部分 !DOCTYPE html> <html> <head> <meta charset="utf-8& ...

  5. python自动化之正则

    import re phoneNumRegex=re.compile(r'\d\d\d-\d\d\d-\d\d\d\d') mo=phoneNumRegex.search('My number is ...

  6. 一些常用的基础Linux操作指令

    复习的时候顺便分享我学的知识,虽不是什么牛的技术分享,只是一些基础,基础打好了技术慢慢就提高了!一起加油一起共勉! 具体的vi和vim命令集太多了,以后的随笔我也会分享出来,没必要全记住,记住常用的就 ...

  7. 01 Spring Boot 的简单配置和使用

    Spring Boot 简介 使用 Spring Boot 可以让我们快速创建一个基于 Spring 的项目,而让这个 Spring 项目跑起来我们只需要很少的配置就可以了. 创建 Spring Bo ...

  8. [BZOJ4044]Virus synthesis 回文自动机的DP

    4044: [Cerc2014] Virus synthesis Time Limit: 20 Sec  Memory Limit: 128 MB Description Viruses are us ...

  9. 【刷题】BZOJ 3669 [Noi2014]魔法森林

    Description 为了得到书法大家的真传,小E同学下定决心去拜访住在魔法森林中的隐士.魔法森林可以被看成一个包含个N节点M条边的无向图,节点标号为1..N,边标号为1..M.初始时小E同学在号节 ...

  10. 20135239益西拉姆 Linux内核分析 进程的描述和进程的创建

    [益西拉姆 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000] 第六周 进程的描述 ...