Problem Statement

Takahashi has $A$ apple seedlings, $B$ banana seedlings, and $C$ cherry seedlings. Seedlings of the same kind cannot be distinguished.

He will plant these seedlings in his $N$ gardens so that all of the following conditions are satisfied.

  • At least one seedling must be planted in every garden.
  • It is not allowed to plant two or more seedlings of the same kind in the same garden.
  • It is not necessary to plant all seedlings he has.

How many ways are there to plant seedlings to satisfy the conditions? Find the count modulo $998244353$.

Two ways are distinguished when there is a garden with different sets of seedlings planted in these two ways.

Constraints

  • $1 \leq N \leq 5 \times 10^6$
  • $0 \leq A \leq N$
  • $0 \leq B \leq N$
  • $0 \leq C \leq N$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $A$ $B$ $C$

Output

Print the answer.


Sample Input 1

2 2 1 1

Sample Output 1

21

As illustrated below, there are $21$ ways to plant seedlings to satisfy the conditions.

(The two frames arranged vertically are the gardens. $A, B, C$ stand for apple, banana, cherry, respectively.)

如果不考虑每个花园中都要种种子的限制,怎么做?

枚举总共会泼洒几个苹果的种子,几个香蕉的种子,几个樱桃的种子,然后用组合数进行计算。用表达式来写就是 \((\sum\limits_{i=0}^aC_n^i)(\sum\limits_{i=0}^bC_n^i)(\sum\limits_{i=0}^cC_n^i)\)

为了方便,设 \(S(n,m)=\sum\limits_{i=0}^mC_n^i\),上面的表达式可以写作 \(S(n,a)\times S(n,b)\times S(n,c)\)

现在要加上每个花园中都要种种子的条件,明显用容斥原理。

定义 \(f(i)\) 为至多有 \(i\) 个花园中有种子的情况数,那么最终答案为 \(f(n)-f(n-1)+f(n-2)-\cdots\)

我们需要快速算出 \(S(n,m)\),但这不太可能有很好的通项公式。如果 \(n\) 为定值,那就处理一个前缀和就可以了,但现在 \(n\) 不为定值, \(m\) 才是。考虑杨辉三角的转移公式,我们可以发现从 \(S(n,m)\) 到 \(S(n+1,m)\) 的路程中,除了 \(C_n^m\),全部算了两次。可以得到转移式子 \(S(n,m)=S(n-1,m)+C_{n-1}^m\)。所以计算 \(m=a,b,c\) 时的答案,套容斥式子就可以了。

#include<cstdio>
const int P=998244353,N=5e6+5;;
int n,a,b,c,f[N],fa[N],fb[N],fc[N],inv[N],iv[N],ans;
int calc(int x,int y)
{
if(x<y)
return 0;
return 1LL*f[x]*iv[y]%P*iv[x-y]%P;
}
int main()
{
scanf("%d%d%d%d",&n,&a,&b,&c);
iv[0]=iv[1]=inv[1]=f[0]=f[1]=1;
for(int i=2;i<=n;i++)
{
inv[i]=1LL*(P-P/i)*inv[P%i]%P;
iv[i]=iv[i-1]*1LL*inv[i]%P;
f[i]=f[i-1]*1LL*i%P;
}
fa[0]=fb[0]=fc[0]=1;
for(int i=1;i<=n;i++)
{
fa[i]=(fa[i-1]*2LL-calc(i-1,a)+P)%P;
fb[i]=(fb[i-1]*2LL-calc(i-1,b)+P)%P;
fc[i]=(fc[i-1]*2LL-calc(i-1,c)+P)%P;
// printf("%d %d %d\n",fa[i],fb[i],fc[i]);
}
for(int i=0;i<=n;i++)
(ans+=(i&1? -1LL:1LL)*calc(n,i)*fa[n-i]%P*fb[n-i]%P*fc[n-i]%P)%=P;
printf("%d",(ans+P)%P);
}

[ABC235G] Gardens的更多相关文章

  1. Vue.js——使用$.ajax和vue-resource实现OAuth的注册、登录、注销和API调用

    概述 上一篇我们介绍了如何使用vue resource处理HTTP请求,结合服务端的REST API,就能够很容易地构建一个增删查改应用.这个应用始终遗留了一个问题,Web App在访问REST AP ...

  2. Vue.js——基于$.ajax实现数据的跨域增删查改

    概述 之前我们学习了Vue.js的一些基础知识,以及如何开发一个组件,然而那些示例的数据都是local的.在实际的应用中,几乎90%的数据是来源于服务端的,前端和服务端之间的数据交互一般是通过ajax ...

  3. Lesson 8 The best and the worst

    Text Joe Sanders has the most beautiful garden in our town. Nearly everbody enters for 'The Nicest G ...

  4. Lesson 3 Please send me a card

    Text Postcards always spoil my holidays. Last summer, I went to Italy. I visited museums and sat in ...

  5. iis

    IIS架构 1.   概述 为了提高IIS的可靠性,安全性以及可用性,与IIS5.0和以前更早的版本不同,IIS6.0提供了一个全新的IIS架构.这个架构的详细情况如下图所示:             ...

  6. Google Maps API V3 之 路线服务

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  7. Python开发【前端】:jQuery

    jQuery简介 jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设计的宗旨是&qu ...

  8. hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)

    hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...

  9. Quant的笑话

    Q) Why was the FX quant so unlucky with the ladies?A) Because he always kept his dates short. Q) Why ...

  10. XQuery的 value() 方法、 exist() 方法 和 nodes() 方法

    Xml数据类型 /*------------------------------------------------------------------------------+ #| = : = : ...

随机推荐

  1. # Unity 如何获取Texture 的内存大小

    Unity 如何获取Texture 的内存大小 在Unity中,要获取Texture的内存文件大小,可以使用UnityEditor.TextureUtil类中的一些函数.这些函数提供了获取存储内存大小 ...

  2. ​python爬虫——爬取天气预报信息

    在本文中,我们将学习如何使用代理IP爬取天气预报信息.我们将使用 Python 编写程序,并使用 requests 和 BeautifulSoup 库来获取和解析 HTML.此外,我们还将使用代理服务 ...

  3. 算法打卡|Day5 哈希表part01

    哈希表 part01 今日任务 ● 哈希表理论基础 ● 242.有效的字母异位词 ● 349. 两个数组的交集 ● 202. 快乐数 ● 1. 两数之和 目录 哈希表 part01 链表理论基础 Pr ...

  4. Springboot简单功能示例-3 实现基本登录验证

    springboot-sample 介绍 springboot简单示例 跳转到发行版 查看发行版说明 软件架构(当前发行版使用) springboot hutool-all 非常好的常用java工具库 ...

  5. Tarjan强连通分量详解

    1.简介: 在阅读下列内容之前,请务必了解 图论相关概念 中的基础部分. 强连通的定义是:有向图 G 强连通是指,G 中任意两个结点连通. 强连通分量(Strongly Connected Compo ...

  6. C#软件架构设计原则

    软件架构设计原则 学习设计原则是学习设计模式的基础.在实际的开发过程中,并不是一定要求所有的代码都遵循设计原则,而是要综合考虑人力.成本.时间.质量,不刻意追求完美,要在适当的场景遵循设计原则.这体现 ...

  7. CF276C

    题目简化和分析: 属于一种贪心思维,我们想如果要使得和最大,那么就必须保证最大的数乘的次数越多越好,并且排序没有限制,快速累加每个位置出现的次数,所以应该使用线段树差分. 然后排序最大乘最大累加. S ...

  8. 再学Blazor——组件

    Blazor 应用基于组件,组件可以复用和嵌套.本文内容如下: 组件类 组件嵌套 组件参数 组件对象 1. 组件类 所有组件都是继承 ComponentBase 组件基类,razor 文件默认继承 C ...

  9. Emit 实体绑定源码开源,支持类以及匿名类绑定(原创)

    动态实体绑定 主要有以下两种 1.表达式树构建委托 2.Emit构建委托 根据我的经验 Emit 代码量可以更少可以很好实现代码复用 Emit实践开源项目地址跳转 https://www.cnblog ...

  10. 虹科案例 | 虹科Domo商业智能,助力保险公司逃离繁杂数据池!

    金融行业的发展充满着不确定性,一个具备强大承保能力和精算专业知识的资金池,对于身处该领域的公司和个人都是十分必要的. 在全国城市联盟(NLC)的协助下成立的NCL Mutual会员制互助保险公司,为各 ...