数学 容斥原理

全都是m+n-1,下图都写成m-n-1了,没有脑子o(╥﹏╥)o

数学 容斥原理_第1张图片

 题目链接:214. Devu和鲜花 - AcWing题库

#include 
#define ll long long
using namespace std;
const int mod = 1e9+7;
ll A[25];
ll Pow(ll a, ll k){
    ll ans = 1;
    while(k){
        if(k & 1) ans = ans*a%mod;
        a = a*a%mod;
        k>>=1;
    }
    return ans;
}
ll down = 1;
ll C(ll a, ll b) {
    if(a=(a-b+1); i--) up = i%mod *up %mod;
    return up * Pow(down, mod-2)%mod;
}
int main(){
    int n; scanf("%d", &n);
    ll m; scanf("%lld", &m);
    for(int i=0; i> j & 1) { //i的这一位是1, 则选
                sign *= -1;  //容斥,奇正偶负
                a -= A[j]+1;
            }
        res = ((res + C(a, b) * sign)%mod + mod)%mod;
    }
    cout << (res + mod)%mod;
    return 0;
}

你可能感兴趣的:(算法)