您的位置:首页 > 其它

[子集DP][Lucas定理] BZOJ 4903: [Ctsc2017]吉夫特

2018-01-15 16:32 316 查看

Solution

原来可以把简单的题面写的那么长~

根据Lucas定理,(nm)≡(⌊n2⌋⌊m2⌋)(nmod2mmod2)(mod2)有(00)=1,(01)=0,(10)=1,(11)=1那么当这个柿子成立当且仅当n and m=m啦,那就可以DP了。

跑的真快

#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> Pairs;

const int N = 233333;
const int MOD = 1000000007;

inline char get(void) {
static char buf[100000], *S = buf, *T = buf;
if (S == T) {
T = (S = buf) + fread(buf, 1, 100000, stdin);
if (S == T) return EOF;
}
return *S++;
}
template<typename T>
inline void read(T &x) {
static char c; x = 0; int sgn = 0;
for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
if (sgn) x = -x;
}

int f
, a
;
int n, U, ans;

inline void Add(int &x, int a) {
x += a; while (x >= MOD) x -= MOD;
}

int main(void) {
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
read(n); U = 233333;
for (int i = 1; i <= n; i++) read(a[i]);
for (int i = 1; i <= n; i++) {
for (int T = a[i]; T <= U; T = (T + 1) | a[i])
Add(f[a[i]], f[T]);
Add(ans, f[a[i]]); Add(f[a[i]], 1);
}
cout << ans << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: