题目链接

思路

这个题可以考虑用全部情况减去不合法的情况,来求解。首先需要知道n个点所组成的图总共有\(C(_n^2)\)种,然后用f[n]表示n个点的图联通的方案数。

然后钦定1在联通图里面,考虑不合法的情况。让j个点联通,其他点可以任意连边,这样就可以保证这张图是不连通的。

所以f数组的转移就是

\[f[n]=C(_n^2) - \sum\limits_{i = 1}^{n-1}{f[i] * C(_{n-i}^2)*C(_{n-1}^{i-1})}
\]

这是n方的转移,然后可以用**T优化。然后我不会

O(n^2)代码

#include<cstdio>
#include<iostream>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long ll;
const int N = 5000 + 10,mod = 998244353;
ll C[N][N];
ll read() {
ll x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
void pre() {
C[0][0] = 1;
for(int i = 1;i <= N;++i) {
C[i][0] = 1;
for(int j = 1;j <= i;++j) {
C[i][j] = C[i-1][j] + C[i-1][j-1];
C[i][j] >= mod ? C[i][j] -= mod : 0;
}
}
}
ll f[N];
ll qm(ll x,int y) {
ll ans = 1;
for(;y;y >>= 1,x = x * x % mod)
if(y & 1) ans = ans * x,ans %= mod;
return ans;
}
int main() {
int n = read();
pre();
f[1] = f[2] = 1;
for(int i = 3;i <= n;++i) {
f[i] = qm(2,C[i][2]);
for(int j = 1;j < i;++j) {
f[i] = (f[i] - (f[j] * C[i-1][j-1] %mod * qm(2,C[i-j][2]) % mod) + mod) % mod;
}
}
cout<<f[n];
return 0;
}

正解

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pr;
const double pi=acos(-1);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define Rep(i,u) for(int i=head[u];i;i=Next[i])
#define clr(a) memset(a,0,sizeof a)
#define pb push_back
#define mp make_pair
ld eps=1e-9;
ll pp=998244353;
ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;}
ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;}
ll read(){
ll ans=0;
char last=' ',ch=getchar();
while(ch<'0' || ch>'9')last=ch,ch=getchar();
while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
if(last=='-')ans=-ans;
return ans;
}
//head
#define N 310000
ll f[N],b1[N],b2[N],inv[N],f2[N],b[N],tt[N],e[N],recf[N],recb[N],Sum[N];
int bel[N];
int n;
ll C(int n,int m){
if(n<m)return 0;
if(m==0 || n==m)return 1;
return b[n]*inv[n-m]%pp*inv[m]%pp;
}
void fnt(ll *a,int n,int fl){
for(int i=n>>1,j=1;j<n;j++){
if(i<j)swap(a[i],a[j]);
int k=n>>1;
for(;k&i;i^=k,k>>=1);
i^=k;
}
ll g=powmod(3,(pp-1)/n,pp);
if(fl==-1)g=powmod(g,n-1,pp);
e[0]=1;
for(int i=1;i<n;i++)e[i]=mo(e[i-1]*g,pp);
for(int m=2,t=n>>1;m<=n;m<<=1,t>>=1)
for(int i=0;i<n;i+=m)
for(int j=i;j<i+(m>>1);j++){
ll u=a[j],v=mo(a[j+(m>>1)]*e[(j-i)*t],pp);
a[j]=u+v;
if(a[j]>=pp)a[j]-=pp;
a[j+(m>>1)]=u-v;
if(a[j+(m>>1)]<0)a[j+(m>>1)]+=pp;
}
}
void Add(ll &a,ll b){
a+=b;
if(a>=pp)a-=pp;
}
int get(){
return (rand()<<10)+rand();
}
int main(){
n=read();
b[0]=inv[0]=1;
rep(i,1,n)b[i]=b[i-1]*i%pp,inv[i]=powmod(b[i],pp-2,pp); f[1]=f2[1]=1;
rep(i,1,n)b1[i]=powmod(2,C(i,2),pp); rep(i,1,n)b2[i]=b1[i]*inv[i]%pp;
int nn=256,n2=nn*2;
rep(i,1,n)bel[i]=i/nn;
int num=0;
ll t=powmod(nn*2,pp-2,pp);
rep(i,1,n){
if(i%nn==0){
rep(j,0,nn*2)tt[j]=0;
rep(j,1,bel[i]-1){
int t1=j*n2,t2=(bel[i]-j)*n2;
rep(k,0,nn*2-1)
tt[k]=(tt[k]+recf[t1+k]*recb[t2+k])%pp;
}
fnt(tt,nn*2,-1);
rep(j,0,nn*2-1)Sum[bel[i]*nn+j]=(Sum[bel[i]*nn+j]+tt[j]*t)%pp;
}
f[i]=mo(b1[i]-Sum[i]*b[i-1],pp);
f2[i]=f[i]*inv[i-1]%pp; for(int j=1;j<i && j<nn;j++)
Sum[i+j]=(Sum[i+j]+f2[j]*b2[i]+f2[i]*b2[j])%pp;
if(i<nn)Add(Sum[i+i],f2[i]*b2[i]%pp); if(i%nn==nn-1){
rep(j,0,nn*2)tt[j]=0;
rep(j,bel[i]*nn,i)tt[j%nn]=f2[j];
fnt(tt,nn*2,1);
rep(j,0,nn*2-1)recf[bel[i]*n2+j]=tt[j]; rep(j,0,nn*2)tt[j]=0;
rep(j,bel[i]*nn,i)tt[j%nn]=b2[j];
fnt(tt,nn*2,1);
rep(j,0,nn*2-1)recb[bel[i]*n2+j]=tt[j];
}
}
cout<<f[n]<<endl;
return 0;
}

一言

那是红得像烈焰,像宝石,像盛夏的初恋,比什么都美好的云朵,仿佛天空的一颗心。 ——阿狸·尾巴

[luoguU48834][count]的更多相关文章

  1. nodejs api 中文文档

    文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...

  2. C#中Length和Count的区别(个人观点)

    这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...

  3. [PHP源码阅读]count函数

    在PHP编程中,在遍历数组的时候经常需要先计算数组的长度作为循环结束的判断条件,而在PHP里面对数组的操作是很频繁的,因此count也算是一个常用函数,下面研究一下count函数的具体实现. 我在gi ...

  4. EntityFramework.Extended 实现 update count+=1

    在使用 EF 的时候,EntityFramework.Extended 的作用:使IQueryable<T>转换为update table set ...,这样使我们在修改实体对象的时候, ...

  5. 学习笔记 MYSQL报错注入(count()、rand()、group by)

    首先看下常见的攻击载荷,如下: select count(*),(floor(rand(0)*2))x from table group by x; 然后对于攻击载荷进行解释, floor(rand( ...

  6. count(*) 与count (字段名)的区别

    count(*) 查出来的是:结果集的总条数 count(字段名) 查出来的是: 结果集中'字段名'不为空的记录的总条数

  7. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  8. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  9. [LeetCode] Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

随机推荐

  1. win10远程桌面连接提示身份验证错误,要求的函数不受支持的解决方案

    转自https://www.baidu.com/link?url=67JXh4h79mN47mEenuH_ElGkSh9_GdOiY-Xp9Ihw0_mQIZHrPx-HxY3EIm_nTZKPoRZ ...

  2. Chrome 75 & lazy-loading

    Chrome 75 & lazy-loading https://addyosmani.com/blog/lazy-loading/ https://chromestatus.com/feat ...

  3. 关于IWMS后台登录问题总结

    一.登录后台,点击登录无反应: 1.是因为网站文件夹没有权限,需要右击文件夹,将只读勾选去掉 2.在安全中加入Everyone对象. 二.登录后台后,左边显示不全,是因为会员权限不够,需要给权限.

  4. Navicat软件安装

    Navicat_10.1.7永久注册码 NAVH-WK6A-DMVK-DKW3

  5. scss 转为 less

    tnpm install less-plugin-sass2less -g && sass2less **/*.scss {dir}/{name}.less && rm ...

  6. 简单触发器实例insert

    create or replace trigger tr_tb_if_archivesafter inserton tb_if_archivesfor each rowdeclarepragma au ...

  7. Linux常见操作

    前面的话 本文将详细介绍Linux常见操作 基本概念 Linux严格区分大小写,所有内容以文件形式保存,包括硬件 Linux没有扩展名的概念,不靠扩展名来区分文件类型.但有一些约定俗成的扩展名 压缩包 ...

  8. WSS Process On Causal LTI System

    Consider a real LTI system with a WSS process $x(t)$ as input and WSS process $y(t)$ as output. Base ...

  9. 创建第一个Djiago

    Djiago 目录介绍 mysite/ ├── manage.py # 管理文件 └── mysite # 项目目录 ├── __init__.py ├── settings.py # 配置 ├── ...

  10. vs + babelua + cocos2d-x

    https://blog.csdn.net/dugaoda/article/details/60467037 https://blog.csdn.net/taotanty/article/detail ...