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. Web视频播放之video.js

    h5这么火是有它的理由的,支持原生视频播放,但是目前兼容性还不是很好,因此使用js框架支持网站视频播放是比较不错的选择. 下载video.js,我们可以通过官网去下,但是官网在国外,我尝试了几次均下载 ...

  2. jQuery知识总结(转)

    原文:http://fwhyy.com/2013/04/jquery-knowledge-summary/ 这篇文章在于筛选器的简单例子,让人一看就懂代码的作用 20170223 前言 jQuery一 ...

  3. 通过shell查找访问日志中访问量最大的ip

    日志格式: /Sep/::: +] /Sep/::: +] /Sep/::: +] - /Sep/::: +] - /Sep/::: +] /Sep/::: +] - /Sep/::: +] /Sep ...

  4. First Steps: Command-line

    This brief tutorial will teach how to get up and running with the Flyway Command-line tool. It will ...

  5. c# 之 事务

    SqlTransaction事务的简单例子 { DataTable dt = new DataTable(); System.Data.SqlClient.SqlConnection cnn = ne ...

  6. (zhuan) 大牛讲堂 | 算法工程师入门第二期-穆黎森讲增强学习

    大牛讲堂 | 算法工程师入门第二期-穆黎森讲增强学习 2017-07-13 HorizonRobotics

  7. (zhuan) Recurrent Neural Network

    Recurrent Neural Network 2016年07月01日  Deep learning  Deep learning 字数:24235   this blog from: http:/ ...

  8. 案例1:写一个压缩字符串的方法,例如aaaabbcxxx,则输出a4b2c1x3。

    public static String zipString(String str){ String result = "";//用于拼接新串的变量 char last = str ...

  9. js中获取当前浏览器类型

    本文为博主原创,转载请注明出处: 在应用POI进行导出时,先应用POI进行数据封装,将数据封装到Excel中,然后在进行download下载操作,从而完成 POI导出操作.由于在download操作时 ...

  10. 解决 Boost安装:fatal error: bzlib.h: No such file or directory 问题

    参考: How to install all the boost development libraries? 解决 Boost安装:fatal error: bzlib.h: No such fil ...