日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

loj 300 [CTSC2017]吉夫特 【Lucas定理 + 子集dp】

發布時間:2025/3/20 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 loj 300 [CTSC2017]吉夫特 【Lucas定理 + 子集dp】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接

loj300

題解

orz litble
膜完題解后,突然有一個簡單的想法:
考慮到\(2\)是質數,考慮Lucas定理:
\[{n \choose m} = \prod_{i = 1} {\lfloor \frac{n}{2^{i - 1}} \rfloor \mod 2^i \choose \lfloor \frac{m}{2^{i - 1}} \rfloor \mod 2^i} \pmod 2\]

\[{n \choose m} = \prod_{each.bit.of.n.and.m} {n' \choose m'} \pmod 2\]
如果二進制下有任何一位\(n\)\(0\)\(m\)不為\(0\),那么就會出現\(m' > n'\)的項,結果就為\(0\)
所以結果不為\(0\),當且僅當二進制下\(m\)\(n\)的子集

所以枚舉子集dp即可【\(f[i]\)表示以\(A[u] = i\)\(u\)開頭的合法子序列個數】
\([1,n]\)枚舉子集的復雜度是\(O(3^{log(max\{a_i\})})\)

#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #define LL long long int #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt) #define REP(i,n) for (int i = 1; i <= (n); i++) #define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts(""); using namespace std; const int maxn = 250000,maxm = 100005,INF = 1000000000,P = 1e9 + 7; inline int read(){int out = 0,flag = 1; char c = getchar();while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}return out * flag; } int f[maxn],a[maxn],ans,n; int main(){n = read();REP(i,n) a[i] = read();for (int i = n; i; i--){int u = a[i];for (int j = u; j; j = (j - 1) & u){f[u] = (f[u] + f[j]) % P;}ans = (ans + f[u]) % P;f[u]++;}printf("%d\n",ans);return 0; }

轉載于:https://www.cnblogs.com/Mychael/p/8987024.html

總結

以上是生活随笔為你收集整理的loj 300 [CTSC2017]吉夫特 【Lucas定理 + 子集dp】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。