当前位置:网站首页>Introduction to ACM [inclusion exclusion theorem]
Introduction to ACM [inclusion exclusion theorem]
2022-04-23 02:55:00 【Hui Xiaoge】

It may be fascinating to see the picture , Let's look directly at the example .
Example 1 :

Very classic content exclusion , We can use binary enumeration to enumerate all collections .
For the sign of each set , Is the number of sets in the set . for example :

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL a[25],n,m,sum;
LL solve(LL n)
{
LL sum=0;
for(int i=1;i<(1<<m);i++)// Attention from 1 Start
{
LL temp=n,cnt=-1;
for(int j=0;j<m;j++)
{
if(i>>j&1)
{
temp/=a[j],cnt=cnt*(-1);
}
}
sum=sum+cnt*temp;
}
return sum;
}
int main(void)
{
cin>>n>>m;
for(int i=0;i<m;i++) cin>>a[i];
cout<<solve(n);
return 0;
}
Example 2 :

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=25;
LL l,r,n,a[N];
LL solve(LL x)
{
LL sum=0;
for(int i=1;i<(1<<n);i++)
{
LL temp=x,cnt=-1;
for(int j=0;j<n;j++)
{
if((i>>j)&1==1) temp/=a[j],cnt=cnt*(-1);
}
sum=sum+cnt*temp;
}
return x-sum;
}
int main(void)
{
cin>>l>>r>>n;
for(int i=0;i<n;i++) cin>>a[i];
cout<<solve(r)-solve(l-1);
return 0;
}
版权声明
本文为[Hui Xiaoge]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220657495003.html
边栏推荐
- Kubernetes - detailed explanation of pod
- The interface request takes too long. Jstack observes the lock holding
- [hcip] detailed explanation of six LSAS commonly used by OSPF
- JDBC JDBC
- Store consumption SMS notification template
- Domestic lightweight Kanban scrum agile project management tool
- leangoo脑图-共享式多人协作思维导图工具分享
- 【工欲善其事必先利其器】论文编辑及文献管理(Endnote,Latex,JabRef ,overleaf)资源下载及使用指南
- Probabilistic model of machine learning
- Microservices (distributed architecture)
猜你喜欢

Airtrack cracking wireless network password (Dictionary running method)

Encapsulation of ele table

Day 3 of learning rhcsa

Processes and threads

Flink stream processing engine system learning (III)

Windows MySQL 8 zip installation

Interim summary (Introduction + application layer + transportation layer)

Fashion MNIST dataset classification training

重大危险源企业如何保障年底前完成双预防机制数字化建设任务

LeetCode 1450 - 1453
随机推荐
Intelligent agricultural management model
Linux redis - redis ha sentinel cluster construction details & redis master-slave deployment
[unity3d] rolling barrage effect in live broadcasting room
Interpretation of the future development of smart agriculture
Shell script learning -- practical case
ROP Emporium x86_ 64 7 ~ 8 questions
Shell script learning notes - regular expressions
What is the difference between varchar and char?
First day of rhcsa
Android high-level interview must ask: overall business and project architecture design and reconstruction
Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
The usage of case when and select case when is very easy to use
机器学习(周志华) 第十四章概率图模型
[hcip] detailed explanation of six LSAS commonly used by OSPF
进阶上将程序员必备素质
Classification of technology selection (2022)
Les derniers noeuds K de la liste jz22
重大危险源企业如何保障年底前完成双预防机制数字化建设任务
《信息系統項目管理師總結》第六章 項目人力資源管理