当前位置:网站首页>[4.9 detailed explanation of inclusion exclusion principle]
[4.9 detailed explanation of inclusion exclusion principle]
2022-07-27 00:35:00 【Romantic dog】
Better reading experience \color{red}{ Better reading experience } Better reading experience
thought

seek S = S 1 ∪ S 2 ∪ S 3 S=S_1\cup S_2\cup S_3 S=S1∪S2∪S3 The area of :
It can be seen from the picture that : S = S 1 ∪ S 2 ∪ S 3 = S 1 + S 2 + S 3 − S 1 ∩ S 2 − S 1 ∩ S 3 − S 2 ∩ S 3 + S 1 ∩ S 2 ∩ S 3 \begin{aligned} It can be seen from the picture that :S=&S_1\cup S_2\cup S_3\\ =&S_1+S_2+S_3\\ &-S_1\cap S_2-S_1\cap S_3-S_2\cap S_3\\ &+S_1\cap S_2\cap S_3 \end{aligned} It can be seen from the picture that :S==S1∪S2∪S3S1+S2+S3−S1∩S2−S1∩S3−S2∩S3+S1∩S2∩S3Promotion requirements S = S 1 ∪ S 2 ∪ S 3 ∩ S 4 S=S_1\cup S_2\cup S_3\cap S_4 S=S1∪S2∪S3∩S4 The area of :
S = S 1 ∪ S 2 ∪ S 3 ∩ S 4 = S 1 + S 2 + S 3 + S 4 − S 1 ∩ S 2 − S 1 ∩ S 3 − S 1 ∩ S 4 − S 2 ∩ S 3 − S 2 ∩ S 4 − S 3 ∩ S 4 + S 1 ∩ S 2 ∩ S 3 + S 1 ∩ S 2 ∩ S 4 + S 1 ∩ S 3 ∩ S 4 + S 2 ∩ S 3 ∩ S 4 − S 1 ∩ S 2 ∩ S 3 ∩ S 4 \begin{aligned} S=&S_1\cup S_2\cup S_3\cap S_4\\ =&S_1+S_2+S_3+S_4\\ &-S_1\cap S_2-S_1\cap S_3-S_1\cap S_4-S_2\cap S_3-S_2\cap S_4-S_3\cap S_4\\ &+S_1\cap S_2\cap S_3+S_1\cap S_2\cap S_4+S_1\cap S_3\cap S_4+S_2\cap S_3\cap S_4\\ &-S_1\cap S_2\cap S_3\cap S_4 \end{aligned} S==S1∪S2∪S3∩S4S1+S2+S3+S4−S1∩S2−S1∩S3−S1∩S4−S2∩S3−S2∩S4−S3∩S4+S1∩S2∩S3+S1∩S2∩S4+S1∩S3∩S4+S2∩S3∩S4−S1∩S2∩S3∩S4If we treat area as a set , It is easy to launch :
set up U There are n Different attributes , And the first i This attribute is called P i Possessing attribute P i The elements of form a set S i , that ∣ ⋃ i = 1 n S i ∣ = ∑ i ∣ S i ∣ − ∑ i < j ∣ S i ∩ S j ∣ + ∑ i < j < k ∣ S i ∩ S j ∩ S k ∣ − … + ( − 1 ) m − 1 ∑ a i < a i + 1 ∣ ⋂ i = 1 m S a i ∣ + ⋯ + ( − 1 ) n − 1 ∣ S 1 ∩ ⋯ ∩ S n ∣ namely : ∣ ⋃ i = 1 n S i ∣ = ∑ m = 1 n ( − 1 ) m − 1 ∑ a i < a i + 1 ∣ ⋂ i = 1 m S a i ∣ \begin{aligned} & set up U There are n Different attributes , And the first i This attribute is called P_i Possessing attribute P_i The elements of form a set S_i, that \\\\ &\begin{aligned} \Bigg|\bigcup_{i=1}^{n}S_i\Bigg|=&\sum_i|S_i|-\sum_{i\lt j}|S_i\cap S_j|+\sum_{i\lt j\lt k}|S_i\cap S_j\cap S_k|-\dots\\ &+(-1)^{m-1}\sum_{a_i\lt a_{i+1}}\Bigg|\bigcap_{i=1}^mS_{a_i}\Bigg|+\dots+(-1)^{n-1}|S_1\cap\dots\cap S_n|\\ \end{aligned}\\\\ & namely :\\\\ &\Bigg|\bigcup_{i=1}^{n}S_i\Bigg|=\sum_{m=1}^n(-1)^{m-1}\sum_{a_i\lt a_{i+1}}\Bigg|\bigcap_{i=1}^mS_{a_i}\Bigg| \end{aligned} set up U There are n Different attributes , And the first i This attribute is called Pi Possessing attribute Pi The elements of form a set Si, that ∣∣i=1⋃nSi∣∣=i∑∣Si∣−i<j∑∣Si∩Sj∣+i<j<k∑∣Si∩Sj∩Sk∣−…+(−1)m−1ai<ai+1∑∣∣i=1⋂mSai∣∣+⋯+(−1)n−1∣S1∩⋯∩Sn∣ namely :∣∣i=1⋃nSi∣∣=m=1∑n(−1)m−1ai<ai+1∑∣∣i=1⋂mSai∣∣
Template example 890. The number divisible
Given an integer n and m A different prime number p1,p2,…,pm.
Please find out 1∼n Middle energy quilt p1,p2,…,pm How many integers are divided by at least one number in .
Input format
The first line contains integers n and m.
The second line contains m A prime number .
Output format
Output an integer , Represents the number of integers that satisfy the condition .
Data range
1≤m≤16,
1≤n,pi≤109
sample input :
10 2
2 3
sample output :
7
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=20;
int p[N];
int main(){
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++) cin>>p[i];
LL res=0;
for(int i=1;i<1<<m;i++){
// 1~2^m-1 These numbers represent 2^m-1 Different items
LL t=1,s=0; //s Represents the number of collections contained in the items of the current enumeration
for(int j=0;j<m;j++){
// Look at the item j Whether the bit contains ,1 The representative contains ,0 Does not include
if(i>>j&1){
// choose
if(t*p[j]>n){
// here n/t = 0, direct break that will do
t=-1;
break;
}
t*=p[j];
s++;
}
}
if(t!=-1){
if(s%2) res+=n/t; // Add the number of odd items
else res-=n/t; // Subtract the number of even items
}
}
cout<<res<<endl;
return 0;
}
边栏推荐
- 7_主成分分析法(Principal Component Analysis)
- Visual studio C cs0006 C failed to find metadata file
- Signal and system learning zero input response
- 【 Educational Codeforces Round 132 (Rated for Div. 2) A·B·C】
- Based on the theoretical principle and simulation results of MATLAB spherical decoding, compare 2norm spherical decoding, infinite norm spherical decoding, ML detection
- Web middleware log analysis script 2.0 (shell script)
- Inherit, inherit, inherit
- Deeplabcut uses 1
- C and pointer Chapter 18 runtime environment 18.2 interface between C and assembly language
- Recbole use 1
猜你喜欢

爬虫解析网页的find方法

Web middleware log analysis script 1.0 (shell script)

Signal and system learning zero input response

Matlab based medical imaging technology filtering backprojection simulation, including direct backprojection, S-L filtering, R-L filtering, LeWitt filtering

Configure deeplobcut 1 with your head covered

Convolutional neural network -- lenet (pytorch Implementation)

关于Redis问题的二三事

信号与系统学习零输入响应

【4.9 容斥原理详解】

RecBole使用1
随机推荐
Drawing warehouse-3 (functional image)
C language to find prime numbers, leap years and minimum common multiples and maximum common divisors
CSDN article syntax rules
Recbole use 1
Arcgis和Cass实现断面展高程点
c语言 比大小的多种描述,不要只拘泥于一种写法
公司给了IP地址如何使用(详细版)
Deploy yolov5 error reporting in pycharm
【4.3 欧拉函数详解】
CDs simulation of minimum dominating set based on MATLAB
今日份20220719折腾deeplabcut
torch.相关函数
【4.2 约数】
In JS, the common writing methods and calling methods of functions - conventional writing, anonymous function writing, taking the method as an object, and adding methods to the object in the construct
Go exceed API source code reading (IV) -- save (), SaveAs (name string)
Find method of web page parsing by crawler
2020-12-22最大公因数
解析网页的完整回顾
postman的使用
Uni app learning (II)