【题解】CF997C Sky Full of Stars
【题解】CF997C Sky Full of Stars
为什么我的容斥原理入门题是这道题?????????
\(Part-1\)正向考虑
直接考虑不合法合法的方案吧
所以我们设行有\(i\),列有\(j\)有是不同的颜色
所以分这几种情况讨论:
\\
i=j=0
\\
ij=0,i+j\not=0
\]
考虑到\(i=j=0\)对答案没有贡献,所以我们考虑第一式和第三式吧
第三式简单一点,情况就是这样的:

方案数还是比较显然的(我说显然是因为是可以通过我努力思考得到,不是我可以秒杀...)
还要试推算一个容斥系数,最终就是
\]
第二式,情况就是这样的:

这种情况下,确定了一种就确定了所有颜色,枚举\(i,j\)吧
\]
然而我们需要\(O(nlogn)\)所以我们考虑对式子变形一下,把所有(部分)\(i\)提出来
\]
把\(j\)的拿出来二项式定理化一下,有些技巧性。
\\
=-3^{n(n-i)}+\Sigma_{j=0}^n C_n^j(3^{n-i})^{n-j}(-1)^j
\\
=-3^{n(n-i)}+(3^{n-i}-1)^n
\]
所以
\]
于是答案就是
\]
复杂度\(O(nlogn)\)
呼呼呼 好难QAQ
\(part-2\)反向考虑

直接蒯了,有没有发现形式很相似?数学真奇妙hhh
给\(2\)号代码吧
#include<bits/stdc++.h>
using namespace std;typedef long long ll;
#define RP(t,a,b) for(register int t=(a),edd=(b);t<=edd;++t)
#define DRP(t,a,b) for(register int t=(a),edd=(b);t>=edd;--t)
#define ERP(t,a) for(register int t=head[a];t;t=e[t].nx)
#define int long long
const int mod=998244353;
inline int ksm(int base,int p){register int ret=1;base%=mod;
for(register int t=p;t;t>>=1,base*=base,base%=mod)if(t&1) ret*=base,ret%=mod; return ret%mod;
}
const int maxn=1e6+5;
int fac[maxn];
int inv[maxn];
int ans;
int n;
inline int C(int n,int m){return (fac[n]*inv[m]%mod)*inv[n-m]%mod;}
signed main(){
#ifndef ONLINE_JUDGE
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
#endif
cin>>n;
inv[0]=fac[0]=1;
RP(t,1,n) fac[t]=fac[t-1]*t%mod,inv[t]=inv[t-1]*ksm(t,mod-2LL)%mod;
ans=ksm(3,n*n)%mod;
ans=(ans-ksm(ksm(3,n)-3LL+mod,n)+mod)%mod;
RP(t,1,n){
register int q=C(n,t)*(3LL*ksm(ksm(3,n-t)-1LL,n)%mod+(ksm(3,n*(n-t))*((ksm(3,t)-3LL+mod)%mod))%mod)%mod;
if(t&1) ans=(ans+q)%mod;
else ans=((ans-q)%mod+mod)%mod;
}
ans=(ans%mod+mod)%mod;
cout<<ans<<endl;
}
【题解】CF997C Sky Full of Stars的更多相关文章
- CF997C Sky Full of Stars
CF997C Sky Full of Stars 计数好题 在Ta的博客查看 容斥式子:发现只要每个钦定方案的贡献都考虑到再配上容斥系数就是对的 O(n^2)->O(n) 把麻烦的i=0,j=0 ...
- 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) ...
- cf997C. Sky Full of Stars(组合数 容斥)
题意 题目链接 \(n \times n\)的网格,用三种颜色染色,问最后有一行/一列全都为同一种颜色的方案数 Sol Orz fjzzq 最后答案是这个 \[3^{n^2} - (3^n - 3)^ ...
- Codeforces 997 C - Sky Full of Stars
C - Sky Full of Stars 思路: 容斥原理 题解:http://codeforces.com/blog/entry/60357 注意当i > 1 且 j > 1,是同一种 ...
- [CF997C]Sky Full of Stars_二项式反演_等比数列_容斥原理
Sky Full of Stars 题目链接:http://codeforces.com/problemset/problem/997/C 数据范围:略. 题解: 首先考虑拟对象,如果至少有一行完全相 ...
- codeforces 997C.Sky Full of Stars
题目链接:codeforces 997C.Sky Full of Stars 一道很简单(?)的推式子题 直接求显然不现实,我们考虑容斥 记\(f(i,j)\)为该方阵中至少有\(i\)行和\(j\) ...
- [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)
[Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...
- codeforces997C Sky full of stars
传送门:http://codeforces.com/problemset/problem/997/C [题解] 注意在把$i=0$或$j=0$分开考虑的时候,3上面的指数应该是$n(n-j)+j$ 至 ...
- 题解报告:hdu 1541 Stars(经典BIT)
Problem Description Astronomers often examine star maps where stars are represented by points on a p ...
随机推荐
- Mac 安装brew和安装composer
一.安装brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/mast ...
- ArcObject开发,“异常在 ESRI.ArcGIS.Version.dll”错误
“System.DllNotFoundException”类型的未经处理的异常在 ESRI.ArcGIS.Version.dll 中发生 其他信息: 无法加载 DLL“ArcGISVersion.dl ...
- 单源最短路Dijstra算法
Dijstra算法是寻找从某一顶点i出发到大其他顶点的最短路径.Distra算法的思想与Prim算法很像,它收录顶点的规则是按照路径长度递增的顺序收录的.设v0是源顶点,我们要寻找从v0出发到其他任意 ...
- mac下安装好sencha cmd后每次都需要输入source ~/.bash_profile
解决办法: 在终端输入vim ~/.zshrc加一句 source ~/.bash_profile
- cordova 中de.sitewaerts.cordova.documentviewer 插件 看pdf图片缩略图与实际图片不一致
//if (document == nil) // Unarchive failed so create a new ReaderDocument object //{ document = [[Re ...
- ZT:成熟是一种明亮而不刺眼的光辉
成熟是一种明亮而不刺眼的光辉, 一种圆润而不腻耳的音响, 一种不再需要对别人察言观色的, 一种终于停止向周围申诉求告的大气, 一种不理会哄闹的微笑, 一种洗刷了偏激的冷漠, 一种无需声张的厚实, 一种 ...
- 《linux 内核全然剖析》 mktime.c
tm结构体的定义在time.h里面 struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_y ...
- Android开发有用的三方网站
聚合数据-免费数据调用 https://www.juhe.cn/ 有赞- 免费的微商城 http://youzan.com/ 秀米微信图文编辑器 http://xiumi.us/ 禅道项目管理软件 h ...
- poj1649 Rescue(BFS+优先队列)
Rescue Time Limit: 2 Seconds Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...
- VMware Workstation 永久许可证密钥
VMware是功能最强大的虚拟机软件,用户可在虚拟机同时运行各种操作系统,进行开发.测试.演示和部署软件,虚拟机中复制服务器.台式机和平板环境,每个虚拟机可分配多个处理器核心.主内存和显存. VMwa ...