C - Sky Full of Stars

思路:

容斥原理

题解:http://codeforces.com/blog/entry/60357

注意当i > 1 且 j > 1,是同一种颜色

代码:

#include<iostream>
#include<cstdio>
#include<queue>
#include<deque>
#include<set>
#include<cstring>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int MOD = ; LL q_pow(LL n, LL k) {
LL ans = ;
while(k) {
if(k&) ans = (ans * n) % MOD;
n = (n*n) % MOD;
k >>= ;
}
return ans;
}
int main() {
int n;
scanf("%d", &n);
LL res = , t = , sign = -;
for (int i = ; i <= n; i++) {
t = (t * (n-i+)) % MOD;
t = (t * q_pow(i, MOD - )) % MOD;
sign = -sign;
LL tt = q_pow(, 1LL*n*(n-i)+i);
res = (res + tt*t*sign) % MOD;
}
res = (res * ) % MOD;
res = (res + MOD) % MOD;
LL ans = ;
t = , sign = -;
for (int i = ; i < n; i++) {
LL tt = q_pow( - q_pow(, i), n);
tt = (tt - q_pow( - q_pow(, i), n)) % MOD;
ans = (ans + tt*t*sign) % MOD;
t = (t * (n-i)) % MOD;
t = (t * q_pow(i+, MOD-)) % MOD;
sign = -sign;
}
ans = (ans * ) % MOD;
ans = (ans + MOD) % MOD;
printf("%lld\n", (res + ans) % MOD);
return ;
}

Codeforces 997 C - Sky Full of Stars的更多相关文章

  1. codeforces 997C.Sky Full of Stars

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

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

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

  3. CF997C Sky Full of Stars

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

  4. 【题解】CF997C Sky Full of Stars

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

  5. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

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

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

  7. codeforces997C Sky full of stars

    传送门:http://codeforces.com/problemset/problem/997/C [题解] 注意在把$i=0$或$j=0$分开考虑的时候,3上面的指数应该是$n(n-j)+j$ 至 ...

  8. Codeforces 835C - Star sky - [二维前缀和]

    题目链接:http://codeforces.com/problemset/problem/835/C 题意: 在天空上划定一个直角坐标系,有 $n$ 颗星星,每颗星星都有坐标 $(x_i,y_i)$ ...

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

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

随机推荐

  1. 【Selenium专题】元素定位之CssSelector

    CssSelector是我最喜欢的元素定位方法,Selenium官网的Document里极力推荐使用CSS locator,而不是XPath来定位元素,原因是CSS locator比XPath loc ...

  2. spring 配置文件属性设置默认值以及读取环境变量值

    在 Spring 中为 javabean 注入属性文件中的属性值一般人都知道的,可以通过 org.springframework.beans.factory.config.PropertyPlaceh ...

  3. Introduction To Machine Learning Self-Evaluation Test

    Preface Section 1 - Mathematical background Multivariate calculus take derivatives and integrals; de ...

  4. 原来Github上的README.md文件这么有意思——Markdown语言详解(sublime text2 版本)

    一直想学习 Markdown 语言,想起以前读的一篇 赵凯强 的 博客 <原来Github上的README.md文件这么有意思——Markdown语言详解>,该篇博主 使用的是Mac系统, ...

  5. VSCode 预览 .md 文件

    VSCode安装md插件 选择Extensions, 输入Markdown Theme Kit,下面会出现相应插件,点击install(截图中因为我已经安装,所以是设置) 或者安装插件Markdown ...

  6. ubuntu18.04无法安装libesd0-dev【学习笔记】

    执行如下命令安装: sudo apt-get install libesd0-dev 却报了这个错误: 解决办法: sudo vim /etc/apt/sources.list //在行尾添加如下两行 ...

  7. noip模拟【service】

    service [问题描述] 一家公司为它在各地的用户提供服务,公司有三名负责这项工作的员工,分别编号为1,2,3,服务的地点有n个,分别编号为1,2,3,...n,把从编号为p的服务地点直接到达编号 ...

  8. 【Dalston】【第四章】容错保护(Hystrix)

    我们在实践微服务架构时,通常会将业务拆分成一个个微服务,微服务之间通过网络进行通信,进行互相调用,造成了微服务之间存在依赖关系.我们知道由于网络原因或者自身的原因,服务并不能保证服务的100%可用,如 ...

  9. ps2016新功能

    1             内容识别缩放(alt ctrl shift c) 2            内容感知移动 3            画笔大小和画笔硬度调整 alt + 鼠标右键:上下为硬度 ...

  10. 【C#】Using的一个比较好的语言文字解释

    其实很早就开始使用using了.但是对这个语法糖我自己一直没有总结也没有一个很好的文字描述解释.今天看其他的博文的时候发现有人对其做了简单的解释我觉得很好,很适合一种讲解.于是抄录下来 using ( ...