当前位置:网站首页>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
边栏推荐
- MySQL / SQL Server判断表或临时表存在则删除
- Decision tree principle of machine learning
- Log4j知识点记录
- OCR recognition PDF file
- Chapter VII project communication management of information system project manager summary
- 1215_ Hello world used by scons
- Encapsulation of ele table
- JZ35 复杂链表的复制
- Airtrack cracking wireless network password (Dictionary running method)
- Linux Redis ——Redis HA Sentinel 集群搭建详解 & Redis主从部署
猜你喜欢
期中汇总(概论+应用层+运输层)
leangoo脑图-共享式多人协作思维导图工具分享
Implementation of distributed scenario business operation log (based on redis lightweight)
Android high-level interview must ask: overall business and project architecture design and reconstruction
工业互联网+危化安全生产综合管理平台怎样建
Specific field information of MySQL export table (detailed operation of Navicat client)
Innovation and management based on Scrum
机器学习(周志华) 第十四章概率图模型
Processes and threads
【Hcip】OSPF常用的6种LSA详解
随机推荐
Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
基于多态的职工管理系统源码与一些理解
Day 4 of learning rhcsa
Step principle of logical regression in machine learning
First day of rhcsa
Probabilistic model of machine learning
Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow
Looking for a job, writing a resume to an interview, this set of information is enough!
Résumé du gestionnaire de projet du système d'information Chapitre VI gestion des ressources humaines du projet
JSON data text
Error installing Mongo service 'mongodb server' on win10 failed to start
Reverse a linked list < difficulty coefficient >
Get together to watch (detailed version) eat a few cents a day
Microservices (distributed architecture)
Classification of technology selection (2022)
ele之Table表格的封装
Publish to NPM?
The difference between encodeuri and encodeuricomponent
《信息系統項目管理師總結》第六章 項目人力資源管理
Log4j知识点记录