The 2023 ICPC Asia Hefei Regional Contest

目录

B. Queue Sorting


应该还会再补几题

B. Queue Sorting

题解:

Dilworth定理:

【偏序关系与偏序集、Hasse图、极大元、极小元、全序关系、最大元、良序集/三小时讲不完离散数学之集合论/考研复试/期末复习考前冲刺/近世代数/抽象代数】https://www.bilibili.com/video/BV1FK4y1i7FP?vd_source=8dcdcdf1464ff87d2684660b142a2bfe

偏序集-Dilworth定理_偏序集的例子-CSDN博客

#define int long long//__int128 2^127-1(GCC)
#define PII pair<int,int>
const int inf = 0x3f3f3f3f3f3f3f3f, N = 1e5 + 5, mod = 998244353;
class modint {
public:int x;modint(int o = 0) { o %= mod; x = o >= 0 ? o : mod + o; }modint& operator = (int o) { o %= mod; return  x = o >= 0 ? o : mod + o, *this; }modint& operator +=(modint o) { return x = x + o.x >= mod ? x + o.x - mod : x + o.x, *this; }modint& operator -=(modint o) { return x = x - o.x < 0 ? x - o.x + mod : x - o.x, * this; }modint& operator *=(modint o) { return x = x * o.x % mod, *this; }modint& operator ^=(int b) {modint a = *this, c = 1;for (; b; b >>= 1, a *= a)if (b & 1)c *= a;return x = c.x, *this;}modint& operator /=(modint o) { return *this *= o ^= mod - 2; }friend modint operator +(modint a, modint b) { return a += b; }friend modint operator -(modint a, modint b) { return a -= b; }friend modint operator *(modint a, modint b) { return a *= b; }friend modint operator /(modint a, modint b) { return a /= b; }friend modint operator ^(modint a, int b) { return a ^= b; }friend bool operator ==(modint a, int b) { return a.x == b; }friend bool operator !=(modint a, int b) { return a.x != b; }bool operator ! () { return !x; }modint operator - () { return x ? mod - x : 0; }bool operator <(const modint& b)const { return x < b.x; }bool operator >(const modint& b)const { return x > b.x; }
};
inline modint qpow(modint x, int y) { return x ^ y; }
int fpow(int x, int r)
{int result = 1;while (r){if (r & 1)result = result * x % mod;r >>= 1;x = x * x % mod;}return result;
}namespace binom {int fac[N], ifac[N];int __ = []{fac[0] = 1;for (int i = 1; i <= N - 5; i++)fac[i] = fac[i - 1] * i % mod;ifac[N - 5] = fpow(fac[N - 5], mod - 2);for (int i = N - 5; i; i--)ifac[i - 1] = ifac[i] * i % mod;return 0;}();inline int C(int n, int m){if (n < m || m < 0)return 0;return fac[n] * ifac[m] % mod * ifac[n - m] % mod;}inline int A(int n, int m){if (n < m || m < 0)return 0;return fac[n] * ifac[n - m] % mod;}
}
using namespace binom;
void add(int& x, const int& y) {(x += y) %= mod;
}
signed main()
{ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);int n;cin >> n;vector<int>a(n + 1), pre(n + 1);for (int i = 1; i <= n; i++) {cin >> a[i];pre[i] = pre[i - 1] + a[i];}vector<vector<modint>>dp(n + 1, vector<modint>(pre[n] + 2));dp[1][pre[1] + 1] = 1;for (int i = 1; i < n; i++) {for (int j = 1; j <= pre[i] + 1; j++) {for (int x = 0; x < a[i + 1]; x++) {for (int k = 1; k < j; k++) {dp[i + 1][x + k + 1] += dp[i][j] * C(j - k + a[i + 1] - x - 2, a[i + 1] - x - 1);}}dp[i + 1][a[i + 1] + j] += dp[i][j];}}modint ans = 0;for (int i = 1; i <= pre[n]+1; i++) {ans += dp[n][i];}cout << ans.x << "\n";}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/690329.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

NX二次开发,在指定的装配节点下新建或者添加组件

目录 一、概述 二、存在的问题 三、在指定的装配节点下新建或者添加组件的实现 四、结果显示 一、概述 最近学习装配内容&#xff0c;说一说体会吧&#xff0c;用起来很爽&#xff0c;开发起开是真的别扭啊&#xff0c;而且&#xff0c;网上可以收到的关于装配的知识有很多…

element 输入框禁止输入空格以及复制的值进去删除空格(vue自定义指令)开箱即用

实例图&#xff1a; 代码&#xff1a; //输入框禁止输入空格 Vue.directive(noSpace, {bind(el) {//禁止输入空格el.addEventListener("keydown", function (event) {if (event.keyCode 32) {event.preventDefault();}});//复制值时去掉空格el.addEventListener(&q…

PY32F403系列单片机,32位M4内核MCU,主频最高144MHZ

PY32F403系列单片机是基于Arm Cortex-M4核的32位通用微控制器产品。内置的FPU和DSP功能支持浮点运算和全部DSP指令。通过平衡成本&#xff0c;性能&#xff0c;功耗来获得更好的用户体验。 PY32F403单片机典型工作频率可达144MHZ&#xff0c;内置高速存储器&#xff0c;丰富的…

Android Studio连接MySQL8.0

【序言】 移动平台这个课程要做一个app的课设&#xff0c;我打算后期增加功能改成毕设&#xff0c;就想要使用MySQL来作为数据库&#xff0c;相对于SQLlite来说&#xff0c;我更熟悉MySQL一点。 【遇到的问题】 一直无法连接上数据库&#xff0c;开始的时候查了很多资料&#…

【C语言】/*操作符(上)*/

目录 一、算数操作符&#xff1a;、-、*、/、% 1.1 和 - 1.2 * 1.3 / 1.4 % 二、赋值操作符&#xff1a; 和符合赋值 2.1 连续赋值 2.2 复合赋值(自操作) 三、单目操作符&#xff1a;、--、(正号)、-(负号) 3.1 和 -- 3.1.1 前置 3.1.2 后置 3.1.3 前置-- …

【RAG 论文】Contriever:对比学习来无监督训练文本嵌入模型

论文&#xff1a;Unsupervised Dense Information Retrieval with Contrastive Learning ⭐⭐⭐⭐⭐ Facebook Research, arXiv:2112.09118 Code&#xff1a;github.com/facebookresearch/contriever 一、论文速读 本文使用对比学习的方法来对文本检索模型做无监督学习训练&am…

数据结构(一)绪论

2024年5月11日 一稿 数据元素数据项 逻辑结构 集合 线性结构 树形结构 图结构 物理结构 数据运算 算法 时间复杂度

【贪心算法】哈夫曼编码Python实现

文章目录 [toc]哈夫曼编码不同编码方式对比前缀码构造哈夫曼编码哈夫曼算法的正确性贪心选择性质证明 最优子结构性质证明 总结 Python实现时间复杂性 哈夫曼编码 哈夫曼编码是广泛用于数据文件压缩的十分有效的编码方法&#xff0c;其压缩率通常为 20 % 20\% 20%到 90 % 90\%…

Cloud Translation 价格

Cloud Translation 价格 您需要按月为 Cloud Translation 处理的内容量付费。您需要支付的具体费用取决于您使用的 API 方法和翻译模型。所列价格以美元 (USD) 为单位。 如果您使用非美元货币付费&#xff0c;请参阅 Cloud Platform SKU 上以您的币种列出的价格。 如需详细了解…

机器学习算法应用——CART决策树

CART决策树&#xff08;4-2&#xff09; CART&#xff08;Classification and Regression Trees&#xff09;决策树是一种常用的机器学习算法&#xff0c;它既可以用于分类问题&#xff0c;也可以用于回归问题。CART决策树的主要原理是通过递归地将数据集划分为两个子集来构建决…

怎么制作流程图?介绍制作方法

怎么制作流程图&#xff1f;在日常生活和工作中&#xff0c;流程图已经成为我们不可或缺的工具。无论是项目规划、流程优化&#xff0c;还是学习理解复杂系统&#xff0c;流程图都能帮助我们更直观地理解和表达信息。然而&#xff0c;很多人可能并不清楚&#xff0c;其实制作流…

12、FreeRTOS信号量(semaphore)

文章目录 一、信号量的特性1.1 使用场景1.2 什么是信号量1.3 信号量和队列的区别1.4 两种信号量的对比 二、二值信号量/计数信号量2.1 什么是二值信号量2.2 什么是计数信号量2.2 (二值信号量/计数信号量) 相关API 三、互斥量(mutex)3.2 什么是优先级翻转3.3 互斥量的使用场合3.…