JZOJ 5351. 【NOIP2017提高A组模拟9.7】简单无向图
题目大意
给定 \(n\) 个度数为 \(\in [1,2]\) 之间的点,求能组成多少种简单无向图(可不连通,点与点之间有别)
分析
显然答案只与 \(n1,n2\) 有关
那么 \(dp\)?(我也不知道为什么)
设 \(f_{i,j}\) 表示当前状态的图用了 \(i\) 个点,目前其度数为 \(1\);\(j\) 同理,度数为 \(2\)
四种转移:
- 加入两个度数为 \(1\) 的点,构成一条新链
- 加入度数形如 \(1-2-1\) 一条链
- 在某条链中插入两个度数为 \(2\) 的点
- 变链成环,加入三个度数为 \(2\) 的点
我也不知道为什么这么转移
然后具体统计看代码
\(Code\)
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 2005;
const LL P = 998244353;
int d[N] , n , n1 , n2;
LL ans , f[N][N];
int main()
{
freopen("graph.in" , "r" , stdin);
freopen("graph.out" , "w" , stdout);
scanf("%d" , &n);
for(register int i = 1; i <= n; i++)
scanf("%d" , &d[i]) , (d[i] == 1 ? n1++ : n2++);
f[0][0] = 1;
for(register int j = 0; j <= n2; j++)
for(register int i = 0; i <= n; i++)
{
if (!f[i][j]) continue;
if (!j) f[i + 2][j] = (f[i + 2][j] + f[i][j] * (i + 1)) % P;
f[i + 2][j + 1] = (f[i + 2][j + 1] + (i + 2) * (i + 1) / 2 % P * f[i][j] % P) % P;
f[i][j + 2] = (f[i][j + 2] + f[i][j] * i % P * (j + 1)) % P;
if (i >= 2) f[i - 2][j + 3] = (f[i - 2][j + 3] + (j + 2) * (j + 1) / 2 % P * f[i][j]) % P;
}
printf("%lld" , f[n1][n2]);
}
JZOJ 5351. 【NOIP2017提高A组模拟9.7】简单无向图的更多相关文章
- JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠
JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...
- [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)
题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ...
- 【NOIP2017提高A组模拟9.7】JZOJ 计数题
[NOIP2017提高A组模拟9.7]JZOJ 计数题 题目 Description Input Output Sample Input 5 2 2 3 4 5 Sample Output 8 6 D ...
- JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团
100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Got ...
- JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线
5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...
- JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器
5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ...
- JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)
5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...
- JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)
5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...
- JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)
5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...
- 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人
[NOIP2017提高A组模拟9.17]信仰是为了虚无之人 Description Input Output Sample Input 3 3 0 1 1 7 1 1 6 1 3 2 Sample O ...
随机推荐
- 轻松玩转sed
sed处理文本方法 1.文本或管道输入 2.读入一行到模式控件 3.sed命令处理 4.输出到屏幕 所以 sed是一个流处理编辑器 sed一次处理一行内容 sed不改变文件内容(可以通过重定向改变文件 ...
- 2022年Kubernetes CKA 认证真题解析完整版
第一题 RBAC授权问题权重: 4% 设置配置环境:[student@node-1] $ kubectl config use-context k8s Context为部署管道创建一个新的Cluste ...
- bug处理记录:Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=512M; support was removed in 8.0
1. 报错: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=512M; support was removed ...
- 手摸手,使用Dart语言开发后端应用,来吧!
前言 这几天连续发了几篇关于 Dart 开发后端应用的文章,主要是介绍了 Dart 的一些优点,比如异步任务,并发处理,编译部署等等. 俗话说,光说不练假把式,今天我们来真正开始一个 Dart 后端应 ...
- 前端内容(HTML CSS javaScript)
前端内容 前端基础之HTML 前端基础之HTML HTML标签使用 HTML之form表单 前端基础之CSS 前端基础之CSS CSS字体颜色 背景 盒子模型 CSS浮动 溢出 头像框 CSS定位 i ...
- elasticsearch倒排索引(全面了解)
SimpleAI推荐语: 前年转过这篇文章,最近在看检索相关论文,发现又有点忘记倒排索引(inverted index)的具体内容,遂翻出来再看看,不得不说,这个漫画画的太好了,娓娓道来,一看就懂,再 ...
- week_7
Andrew Ng 机器学习笔记 ---By Orangestar Week_7 This week, you will be learning about the support vector ma ...
- prometheus-监控docker服务器
1. prometheus-监控docker服务器 prometheus-监控docker服务器 cAdvisor(Container Advisor):用于收集正在运行的容器资源使用和性能信息. 项 ...
- Git和Maven的学习笔记
Git 1.Git简介 Git 是一个免费的.开源的分布式版本控制系统,可以快速高效地处理从小型到大型的各种 项目. Git 易于学习,占地面积小,性能极快. 它具有廉价的本地库,方便的暂存区域和多个 ...
- day03-Spring管理Bean-IOC-01
Spring管理Bean-IOC 1.Spring配置/管理bean介绍 Bean管理包括两方面: 创建bean对象 给bean注入属性 Bean的配置方式: 基于xml文件配置方式 基于注解配置方式 ...