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. Java - ReentrantLock锁分析

    Java - JUC核心类AbstractQueuedSynchronizer(AQS)底层实现 一.  AQS内部结构介绍 JUC是Java中一个包   java.util.concurrent . ...

  2. Nomad 系列-快速上手

    系列文章 Nomad 系列文章 Nomad 重要术语 Nomad 安装设置相关术语 agent - 代理.Agent 是在 Server(服务器) 或 Client(客户端) 模式下运行的 Nomad ...

  3. Antd Form表单中Input输入框 在IE9下按下任何按键都会报校验失败

    antd Form表单中Input输入框 在IE9下按下任何按键都会报校验失败,导致输入框输入不了任何内容! 可能你的react及react-dom版本由于过高导致antd组件不能兼容,需要对reac ...

  4. 第3章 Git最最常用命令大全

    相信来查命令的同学,根本不是来学具体某个命令的作用的,只是想来查看命令的语法,博主深知这一点(因为博主也是这样过来的),相信这篇文章,将会带给你在工作中最常用的命令,让你一打开就是命令大全!! 喜欢这 ...

  5. KRPano最新官方文档中文版

    KRPano最新官方文档中文版: KRPano作为VR全景开发中常用的工具软件,深受广大开发者喜爱,但由于软件本身是国外软件,因此官方的文档都是以英文为主,对于一些国内不太熟悉英文的开发者来说比较不友 ...

  6. c语言代码练习5

    //输入密码,正确就登录,错误重新输入,只能输入三次#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <st ...

  7. FragmentStatePagerAdapter

    public abstract class FragmentStatePagerAdapter extends PagerAdapter java.lang.Object    ↳ android.s ...

  8. 记一次 .NET某新能源检测系统 崩溃分析

    一:背景 1. 讲故事 前几天有位朋友微信上找到我,说他的程序会偶发性崩溃,一直找不到原因,让我帮忙看一下怎么回事,对于这种崩溃类的程序,最好的办法就是丢dump过来看一下便知,话不多说,上windb ...

  9. 从零用VitePress搭建博客教程(2) –VitePress默认首页和头部导航、左侧导航配置

    2. 从零用VitePress搭建博客教程(2) –VitePress默认首页和头部导航.左侧导航配置 接上一节: 从零用VitePress搭建博客教程(1) – VitePress的安装和运行 四. ...

  10. c#组合模式详解

    基础介绍:   组合模式用于表示部分-整体的层次结构.适用于希望用户忽略组合对象与单个对象的不同,用户将统一地使用组合结构中的所有对象的情况.   顾名思义,什么叫部分-整体,比如常见的前端UI,一个 ...