cfy有n种花,每种各1朵,需要从中选出1种或多种来扎成花束,要求花的朵数不能是a或b,问可以制作多少种不同的花束?结果对1E9+7取模。
2<=n<=1E9; 1<=a<b<=min(n,2E5)
每朵花都有选与不选两种情况,去掉都不选的情况,共2^n-1种方案。然后再减掉选a种和选b种的情况,方案数分别为C(n,a)和C(n,b),这里n比较大,要用定义算。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,a,b) for(int i=b; i>=a; i--)
template<int MOD>
struct MInt {
int x;
int norm(int u) const {u%=MOD; if(u<0) u+=MOD; return u;}
MInt(int v=0):x(norm(v)) {}
int val() const {return x;}
MInt operator-() const {return MInt(norm(MOD-x));}
MInt inv() const {assert(x!=0); return power(MOD-2);}
MInt &operator*=(const MInt &o) {x=norm(x*o.x); return *this;}
MInt &operator+=(const MInt &o) {x=norm(x+o.x); return *this;}
MInt &operator-=(const MInt &o) {x=norm(x-o.x); return *this;}
MInt &operator/=(const MInt &o) {*this *= o.inv(); return *this;}
friend MInt operator*(const MInt &a, const MInt &b) {MInt ans=a; ans*=b; return ans;}
friend MInt operator+(const MInt &a, const MInt &b) {MInt ans=a; ans+=b; return ans;}
friend MInt operator-(const MInt &a, const MInt &b) {MInt ans=a; ans-=b; return ans;}
friend MInt operator/(const MInt &a, const MInt &b) {MInt ans=a; ans/=b; return ans;}
friend std::istream &operator>>(std::istream &is, MInt &a) {int u; is>>u; a=MInt(u); return is;}
friend std::ostream &operator<<(std::ostream &os, const MInt &a) {os<<a.val(); return os;}
MInt power(int b) const {int r=1, t=x; while(b){if(b&1) r=r*t%MOD; t=t*t%MOD; b/=2;} return MInt(r);}
};
using mint = MInt<1000000007>;
mint comb(int n, int k) {
mint r = 1;
rep(i,1,k) r *= n-i+1;
rep(i,1,k) r /= i;
return r;
}
void solve() {
int n, a, b;
cin >> n >> a >> b;
mint ans = 2;
ans = ans.power(n) - 1;
ans -= comb(n,a);
ans -= comb(n,b);
cout << ans << "\n";
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
while (t--) solve();
return 0;
}
标签:return,带朵,int,mint,rep,abc156D,ans,扎花,MInt
From: https://www.cnblogs.com/chenfy27/p/18064239