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);
//headconst int MOD = 998244353;LL q_pow(LL n, LL k) {LL ans = 1;while(k) {if(k&1) ans = (ans * n) % MOD;n = (n*n) % MOD;k >>= 1;}return ans;
}
int main() {int n;scanf("%d", &n);LL res = 0, t = 1, sign = -1;for (int i = 1; i <= n; i++) {t = (t * (n-i+1)) % MOD;t = (t * q_pow(i, MOD - 2)) % MOD;sign = -sign;LL tt = q_pow(3, 1LL*n*(n-i)+i);res = (res + tt*t*sign) % MOD;}res = (res * 2) % MOD;res = (res + MOD) % MOD;LL ans = 0;t = 1, sign = -1;for (int i = 0; i < n; i++) {LL tt = q_pow( 1 - q_pow(3, i), n);tt = (tt - q_pow( - q_pow(3, i), n)) % MOD;ans = (ans + tt*t*sign) % MOD;t = (t * (n-i)) % MOD;t = (t * q_pow(i+1, MOD-2)) % MOD;sign = -sign;}ans = (ans * 3) % MOD;ans = (ans + MOD) % MOD;printf("%lld\n", (res + ans) % MOD);return 0;
}

转载于:https://www.cnblogs.com/widsom/p/9306316.html

Codeforces 997 C - Sky Full of Stars相关推荐

  1. 【CodeForces 997C】Sky Full of Stars(组合计数)

    题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...

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

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

  3. 数论五之容斥——硬币购物,Gerald and Giant Chess,幸运数字,Sky Full of Stars,已经没有什么好害怕的了

    容斥的神 [HAOI2008]硬币购物 problem solution code CF559C Gerald and Giant Chess problem solution code [SCOI2 ...

  4. CodeForces 997 简要题解

    Convert to Ones 翻转操作实际就是合并两段 000 ,特判全 1" role="presentation" style="position: re ...

  5. CodeForces 997C Sky Full of Stars

    题目:点击打开链接 题意:给n*n个格子,每个格子可以填3种颜色.问有多少种填色方案,至少有一列或一行是同色的. 分析:首先反过来考虑,找不幸运的组合,因为这样便于容斥.  要把列和行分开考虑.  首 ...

  6. CodeForces - 997C Sky Full of Stars

    题面在这里! 题解见注释 /*设至少有i行,j列是一种颜色的方案数为 f(i,j)那么:1.i==0||j==0 时 , f(i,j) = C(n,i) * C(n,j) * 3^( (n-i)*(n ...

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

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

  8. CF997C Sky Full of Stars

    CF997C , Luogu 有一个 \(n \times n ( n \leq 10^6)\)的正方形网格,用红色,绿色,蓝色三种颜色染色,求有多少种染色方案使得至少一行或一列是同一种颜色.结果对 ...

  9. CF 997C Sky Full of Stars

    传送门 题目大意 思路 参考代码 总结 传送门 题目大意 有一个 n×n(n≤106)n×n(n≤106)n \times n \pod {n \le 10^6} 的正方形网格.用三种颜色对每个格子染 ...

最新文章

  1. JOptionPane
  2. C_Imap 邮件的imap
  3. 知识图谱 (知识计算推理)
  4. Java设计模式之双向责任链COR模式
  5. 动态加入JS及加入CSS
  6. 填写【2fpmi2j】
  7. [Html]Jekyll 代码高亮的几种选择
  8. 如何在线伪造邮箱发件人,用任意邮箱发送邮件
  9. 【webshell分析】PHP大马分析
  10. JSP入门必须了解的知识详解
  11. 3脚送话器内部电路图_电话机维修送话电路故障
  12. fifo算法原理及fifo置换算法
  13. 什么是商业智能(BI)?
  14. 关于Palantir—第四部分:Palantir应用程序
  15. 量化投资学习-7:图解股市的基本面、技术面、市场环境面的关系
  16. 小米4 第三方re奇兔_再战三年?小米6支持升级Android 11,米10都没它快!
  17. MFC不同窗口之间传递数据
  18. 胡睿:感谢清华大学计算机系的朱仲涛老师
  19. 易语言零基础新手入门系列教程 第一课
  20. idea pom中的依赖加载成功import报红解决方法

热门文章

  1. 使GDAL库支持中文路径或中文文件名的处理方法
  2. 【Ubuntu】解决ubuntu系统root用户下Chrome无法启动问题
  3. 【Qt】Qt再学习(十二):QGraphicsItem
  4. 【Qt】Qt程序编译成功,执行时报错:程序异常结束,crashed
  5. base64 python兼容js_无法在中读取Base64编码的图像节点.js它是从Python发送的
  6. 惠普z840工作站linux,全模块战神 惠普旗舰级Z840工作站评测
  7. oracle字段重复新增错误,oracle在已有重复数据的列上创建唯一约束
  8. 【Linux】 Linux简单操作之网络通信和网络访问
  9. Tomcat下载安装与环境变量的配置
  10. 实对称矩阵的性质_浅谈矩阵的相似对角化(一)