当前位置:网站首页>关于不定方程解的个数的问题
关于不定方程解的个数的问题
2022-07-24 13:42:00 【lAWTYl】
不定方程的解的个数
Lv0
首先我们看这样一个问题,求 ∑ i = 1 n x i = b \sum\limits_{i = 1}^n x_i = b i=1∑nxi=b 的非负整数解的个数。
这个问题就非常简单啊,我们稍微把他转化一下,这个问题就等价于有 n n n 个小朋友分 b b b 个糖果,每个小朋友至少分到 0 0 0 个糖果(好惨啊),求分完糖果的方案数。
然后我们再转化一下问题,现在有 b b b 个糖果排成一排,在其中放 n − 1 n - 1 n−1 个木板(可以有多个木板在同一个格子里),这样就能把这些糖果分成 n n n 部分,求方木板的方案数。
这样就很显然了嘛,答案就是总共有 n + b − 1 n + b - 1 n+b−1 个格子可选,在其中选出 n − 1 n - 1 n−1 个格子的方案数,也就是 C n + b − 1 n − 1 C_{n + b - 1}^{n - 1} Cn+b−1n−1。
Lv1
还有这样一个问题,求 ∑ i = 1 n x i = b \sum\limits_{i = 1}^nx_i = b i=1∑nxi=b 且 x i ≥ l i x_i \geq l_i xi≥li 的非负整数解数。显然我们非常不希望出现后面的约束条件,于是我们考虑这样:
∑ i = 1 n x i = b − ∑ i = 1 n l i \sum_{i = 1}^nx_i = b - \sum_{i = 1}^nl_i i=1∑nxi=b−i=1∑nli
这样一来我们就把问题转化成了第一个问题一样的形式了(就相当于我们减掉了 x i < l i x_i < l_i xi<li 的贡献),答案就是:
a n s = ( n + b − ∑ i = 1 n l i − 1 n − 1 ) ans = \begin{pmatrix} n + b - \sum\limits_{i = 1}^n l_i - 1 \\ n - 1 \end{pmatrix} ans=⎝⎛n+b−i=1∑nli−1n−1⎠⎞
Lv2
最后一个问题,求 ∑ i = 1 n x i = b \sum\limits_{i = 1}^nx_i = b i=1∑nxi=b 且 x i ≤ r i x_i \leq r_i xi≤ri 的非负整数解的个数。这个问题就不像上一个那么好转换了。所以我么考虑容斥掉 x i ≥ r i + 1 x_i \geq r_i + 1 xi≥ri+1 的贡献。
我们令集合 S S S 表示 ∑ i = 1 n ( x i ≥ r i + 1 ) \sum\limits_{i = 1}^n(x_i \geq r_i + 1) i=1∑n(xi≥ri+1) 的二进制集合。这样就相当于求 S = { 0 , 0 , ⋯ , 0 } S = \{ 0, 0, \cdots, 0 \} S={ 0,0,⋯,0} 的时候的答案。我们令 f ( S ) f(S) f(S) 表示该二进制集合为 S S S 时的答案。则有:
f ( S = { 0 , 0 , ⋯ , 0 } ) = t o t − ∑ S ⊂ U ( − 1 ) ∣ S ∣ + 1 f ( S ) f(S = \{0, 0, \cdots, 0\}) = tot - \sum_{S \subset U}(-1)^{|S| + 1}f(S) f(S={ 0,0,⋯,0})=tot−S⊂U∑(−1)∣S∣+1f(S)
其中 t o t tot tot 表示总数,也就是第一个问题的答案。 U = { 0 , 0 , ⋯ , 0 } U = \{ 0, 0, \cdots, 0 \} U={ 0,0,⋯,0} ( n n n 个 0 0 0)。上面这个式子就是容斥原理嘛。
然后其中(等价于第二个问题):
f ( S ) = ( n + b − 1 − ∑ i ∈ S ( r i + 1 ) n − 1 ) f(S) = \begin{pmatrix} n + b - 1 - \sum\limits_{i \in S} (r_i + 1) \\ n - 1 \end{pmatrix} f(S)=(n+b−1−i∈S∑(ri+1)n−1)
于是:
a n s = ( n + b − 1 n − 1 ) − ∑ S ⊂ U ( − 1 ) ∣ S ∣ + 1 f ( S ) = ( n + b − 1 n − 1 ) + ∑ S ⊂ U ( − 1 ) ∣ S ∣ ( n + b − 1 − ∑ i ∈ S ( r i + 1 ) n − 1 ) = ∑ S ⊆ U ( − 1 ) ∣ S ∣ f ( S ) \begin{aligned} ans & = \begin{pmatrix} n + b - 1 \\ n - 1 \end{pmatrix} - \sum_{S \subset U}(-1)^{|S| + 1} f(S) \\ & = \begin{pmatrix} n + b - 1 \\ n - 1 \end{pmatrix} + \sum_{S \subset U} (-1)^{|S|} \begin{pmatrix} n + b - 1 - \sum\limits_{i \in S}(r_i + 1) \\ n - 1 \end{pmatrix} \\ & = \sum_{S \subseteq U} (-1)^{|S|}f(S) \end{aligned} ans=(n+b−1n−1)−S⊂U∑(−1)∣S∣+1f(S)=(n+b−1n−1)+S⊂U∑(−1)∣S∣(n+b−1−i∈S∑(ri+1)n−1)=S⊆U∑(−1)∣S∣f(S)
边栏推荐
- Flink高级特性和新特性(八)v2
- 【无标题】
- Sringboot-plugin-framework 实现可插拔插件服务
- H5py Quick Start Guide
- 数据修改修改
- WSDM 22 | 基于双曲几何的图推荐
- 网络安全——Cookie注入
- Network security - Web penetration testing
- 通配符(泛域名)SSL证书
- Simulate the implementation of the library function memcpy-- copy memory blocks. Understand memory overlap and accurate replication in detail
猜你喜欢

简易订单管理系统小练习

Aggregation measurement of robot swarm intelligence based on group entropy

Network security - file upload blacklist bypass

网络安全——中间人攻击渗透测试

Detailed explanation of odoo JS DoAction

开放环境下的群智决策:概念、挑战及引领性技术

Chapter VI bus

Kunyu(坤舆) 安装 详解

如何生成预期数据?埃默里大学等最新《深度学习可控数据生成》综述,52页pdf涵盖346篇文献全面阐述可控生成技术体系

Thread multithreading
随机推荐
Network security - filtering bypass injection
使用Activiti创建数据库表报错,
Realize a JS lottery?
Network security - file upload content check bypass
How can the easycvr platform access special devices without authentication?
CSDN垃圾的没有底线!
网络安全——服务漏洞扫描与利用
rhce第一次作业
Simulate the implementation of the library function memcpy-- copy memory blocks. Understand memory overlap and accurate replication in detail
Network security - error injection
Happy number ~ ~ ~ (in fact, I'm not happy at all) & ugly number
Representation and basic application of regular expressions
基于群体熵的机器人群体智能汇聚度量
How to configure webrtc protocol for low latency playback on easycvr platform v2.5.0 and above?
R语言使用epiDisplay包的summ函数计算dataframe中指定变量在不同分组变量下的描述性统计汇总信息并可视化有序点图、自定义cex.main参数配置标题文本字体的大小
Mongodb uses mongotemplate operations to add, delete, modify, query, page, sort, aggregate (including embedded data), file upload and download
Aike AI frontier promotion (7.24)
[acm/ two points] two points clear entry-level explanation
Editor formula
支持鹏程系列开源大模型应用生态演化的可持续学习能力探索