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. DBeaver连接Oracle11g数据库

    DBeaver连接Oracle11g数据库 一.准备 (1)dbeaver管理软件 (2)远程连接数据库地址.用户名秘密等 (3)Oracle驱动:ojdbc6.jar工具包 下载地址:https:/ ...

  2. VR AR MR

    VR.AR和MR的区别? VR就是创造一个完全取代现实的世界,让人感觉「我怎么在这里?」 AR则是在现实世界的图像中叠加一些东西,让人感觉「哎?这里多了个本来不存在的东西」 MR则是虚拟物体完全和现实 ...

  3. es破解xpack

    环境:OS:CentOS 7elasticsearch:6.5.0 1.vim LicenseVerifier.java package org.elasticsearch.license; impo ...

  4. Computer Study

    2017.12.15日开始制定长期学习计划: 大二上: 目前短期计划: 1.每天一道PAT乙级(弄完PAT乙级)+校OJ(打基础).   2.先复习C++,17周后开始复习数据结构.(补任务  刚刚发 ...

  5. Python3基础 iter+next 进行迭代时超出了范围 产生StopIteration异常

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. mysql数据库连接的测试代码语句片断

    手动连接数据库 的代码片断, 用于各种数据库的测试... $conn = mysql_connect('localhost', 'root', '') or die('failed to connec ...

  7. P4238 【模板】多项式求逆

    思路 多项式求逆就是对于一个多项式\(A(x)\),求一个多项式\(B(x)\),使得\(A(x)B(x) \equiv 1 \ (mod x^n)\) 假设现在多项式只有一项,显然\(B(x)\)的 ...

  8. 【Hadoop 分布式部署 六:环境问题解决和集群基准测试】

    环境问题: 出现Temporary  failure  in  name  resolutionp-senior-zuoyan.com 的原因有很多,主要就是主机没有解析到, 那就在hadoop的sl ...

  9. vs项目模板

    创建项目模板 Creating a VSIX Deployable Project (or Item) Template with Custom Wizard Support Create a Pro ...

  10. Kylin知识点介绍

    Kylin is an open source Distributed Analytics Engine from eBay Inc.that provides SQL interface and m ...