2019牛客多校四 E. triples II (容斥)
生活随笔
收集整理的這篇文章主要介紹了
2019牛客多校四 E. triples II (容斥)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
大意: 給定$n,a$, 求$n$個$3$的倍數, $or$和為$a$的方案數.
?
?
簡單容斥題
可以求出$f_{x,y}$表示所有$3$的倍數中, 奇數位不超過$x$個$1$, 偶數位不超過$y$個$1$的個數.
假設$a$二進制奇數位$c_1$個$1$,偶數位$c_0$個$1$, 根據容斥就有
$ans=\sum\limits_{i=0}^{c_1}\sum\limits_{j=0}^{c_0}(-1)^{c_0+c_1-i-j}\binom{c_1}{i}\binom{c_0}{j}f_{i,j}^n$
#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include <string.h> #include <bitset> #define REP(i,a,n) for(int i=a;i<=n;++i) #define PER(i,a,n) for(int i=n;i>=a;--i) #define hr putchar(10) #define pb push_back #define lc (o<<1) #define rc (lc|1) #define mid ((l+r)>>1) #define ls lc,l,mid #define rs rc,mid+1,r #define x first #define y second #define io std::ios::sync_with_stdio(false) #define endl '\n' #define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;}) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int P = 998244353, INF = 0x3f3f3f3f; ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;} ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;} inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;} //headconst int N = 63; int C[N][N],f[N][N]; int main() {REP(i,0,N-1) {C[i][0] = 1;REP(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%P;}REP(i,0,N-1) REP(j,0,N-1) REP(ii,0,i) REP(jj,0,j) if ((ii+2*jj)%3==0) {f[i][j] = (f[i][j]+(ll)C[i][ii]*C[j][jj])%P;}int t;scanf("%d", &t);while (t--) {ll n, a;scanf("%lld%lld", &n, &a);n %= P-1;int c[2]{};REP(i,0,N-1) if (a>>i&1) ++c[i&1];int ans = 0;REP(i,0,c[0]) REP(j,0,c[1]) {int ret = (ll)C[c[0]][i]*C[c[1]][j]%P*qpow(f[i][j],n)%P;if (c[0]+c[1]+i+j&1) ret = P-ret;ans = (ans+ret)%P;}printf("%d\n", ans);} }?
轉載于:https://www.cnblogs.com/uid001/p/11258406.html
總結
以上是生活随笔為你收集整理的2019牛客多校四 E. triples II (容斥)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mapping数据列表
- 下一篇: CLOUD信用管理设置