hdu 1796 How many integers can you find 容斥原理
来源:互联网 发布:qpad鼠标知乎 编辑:程序博客网 时间:2024/05/16 14:32
abc=a+b+c-ab-ac-bc+abc
abcd=a+b+c+d-ab-ac-ad-bc-bd-cd+abc+abd+bcd-abcd
.
.
.
dfs枚举,传参保证当前是加还是减,注意输入检查以及<n
#include <stdio.h>#include <vector>#include <algorithm>#include <iostream>using namespace std;typedef long long ll;ll t[20];ll n,ans;int m;ll gcd(ll a,ll b){ return a%b==0?b:gcd(b,a%b);}void dfs(int p,ll num,int flag){ if(p) ans+=flag*n/num; for(int i=p+1;i<=m;i++) { dfs(i,t[i]/gcd(t[i],num)*num,-flag); }}int main(){ while(cin>>n>>m) { for(int i=1;i<=m;i++) { cin>>t[i]; if(t[i]<=0||t[i]>=n) i--,m--; } n--; ans=0; dfs(0,1,-1); cout<<ans<<endl; } return 0;}
4 0
- hdu-1796-How many integers can you find(容斥)
- HDU 1796 How many integers can you find 【容斥】
- HDU 1796 How many integers can you find 容斥原理
- 【容斥原理】HDU-1796-How many integers can you find
- HDU 1796 How many integers can you find(容斥原理)
- hdu 1796 How many integers can you find(容斥原理)
- HDU 1796 容斥原理 How many integers can you find
- hdu 1796 How many integers can you find(容斥原理)
- hdu 1796 How many integers can you find (容斥原理)
- hdu 1796 How many integers can you find 容斥原理
- HDU 1796 How many integers can you find(组合数学-容斥原理)
- HDU 1796 How many integers can you find(组合数学-容斥原理)
- hdu 1796 How many integers can you find(容斥原理)
- hdu 1796 How many integers can you find[经典容斥原理]
- [容斥原理] hdu 1796 How many integers can you find
- hdu 1796 How many integers can you find【容斥原理】
- HDU 1796 How many integers can you find(容斥原理)
- HDU 1796 - How many integers can you find(容斥原理)
- 恒天云技术分享系列(一)—虚拟机热迁移
- iOS开发- 启动动画(动态欢迎界面,非静态Default)
- Xcode工程依赖
- 单片机地址空间,堆栈理解
- 学习网站
- hdu 1796 How many integers can you find 容斥原理
- 代理模式
- 流量经营百科
- 在 Linux 上找出并解决程序错误的主要方法
- 权限模型设计
- 每日必读之:2014-4-16
- 支付宝回调客户端方法
- 传统银行“亮剑”互联网金融 直销银行是利器
- 【ci框架】CI超级对象