数位DP CF388D - Fox and Perfect Sets
一个整数perfect集合满足性质:集合中随意两个整数的异或和仍在这个集合中。
求最大数不超过K的perfect集合的个数。
每一个集合都是一个线性的向量空间。
。能够通过全然的高斯消元得出该空间的基底。。从高位到低位按基底DP。
。
DP[now][num][upper]表示K从左往右第now位空间向量个数为num且集合中最大值是否为K的前now位的基底个数。。。
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <cassert>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#define RD(x) scanf("%d", &x)
#define REP(i, n) for (int i=0; i<(n); i++)
#define FOR(i, n) for (int i=1; i<=(n); i++)
#define pii pair<int, int>
#define mp make_pair
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; using namespace std;
#define N 50
#define M 22222
#define eps 1e-9
#define pi acos(-1.0)
#define inf 0XFFFFFFFll
#define mod 1000000007ll
#define LL long long
int K; LL dp[N][N][2];
LL c[N][N]; int main() {
REP(i, N) REP(j, i + 1) {
if (j == 0 || j == i)
c[i][j] = 1;
else
c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;
}
RD(K);
dp[31][0][1] = 1;
for (int i = 31; i > 0; --i) {
for (int j = 0; j <= 30; ++j) {
for (int k = 0; k < 2; ++k) {
// add new 1 in a new vector
if (!(k == 1 && (K >> (i - 1)) % 2 == 0)) {
int nk = (k == 1 && (K >> (i - 1)) % 2 == 1) ? 1 : 0;
dp[i-1][j+1][nk] += dp[i][j][k];
dp[i-1][j+1][nk] %= mod;
}
// add new 1 in old vectors even
int nk = (k == 1 && (K >> (i - 1)) % 2 == 0) ? 1 : 0;
for (int t = 2; t <= j; t += 2) {
dp[i-1][j][nk] += dp[i][j][k] * c[j][t] % mod;
dp[i-1][j][nk] %= mod;
}
// add new 1 in old vectors odd
if (!(k == 1 && (K >> (i - 1)) % 2 == 0)) {
int nk = (k == 1 && (K >> (i - 1)) % 2 == 1) ? 1 : 0;
for (int t = 1; t <= j; t += 2) {
dp[i-1][j][nk] += dp[i][j][k] * c[j][t] % mod;
dp[i-1][j][nk] %= mod;
}
}
// be zero
nk = (k == 1 && (K >> (i - 1)) % 2 == 0) ? 1 : 0;
dp[i-1][j][nk] += dp[i][j][k];
dp[i-1][j][nk] %= mod;
}
}
}
LL ans = 0;
REP(j, 31) REP(k, 2)
ans = (ans + dp[0][j][k]) % mod;
cout << ans << endl;
return 0;
}
数位DP CF388D - Fox and Perfect Sets的更多相关文章
- BZOJ CF388D. Fox and Perfect Sets [线性基 数位DP]
CF388D. Fox and Perfect Sets 题意:求最大元素\(le n\)的线性空间的个数 给神题跪了 orz 容易想到 每个线性基对应唯一的线性空间,我们可以统计满足条件的对应空间不 ...
- 【做题】CF388D. Fox and Perfect Sets——线性基&数位dp
原文链接https://www.cnblogs.com/cly-none/p/9711279.html 题意:求有多少个非空集合\(S \subset N\)满足,\(\forall a,b \in ...
- Codeforces 388 D. Fox and Perfect Sets
$ >Codeforces \space 388 D. Fox and Perfect Sets<$ 题目大意 : 定义一个完美的集合 \(S\) ,当且仅当 \(S\) 非负非空,且 ...
- codeforces 388D Fox and Perfect Sets(线性基+数位dp)
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mp mak ...
- Codeforces 388D Fox and Perfect Sets
链接:CF388D 题目大意 给定一个数\(n\),求选择\(0 \sim n\)中任意个数的数字组成的集合\(S\)中,有多少满足若\(a\in S,b\in S\),则\(a \bigoplus ...
- Codeforces Round #460 (Div. 2) B Perfect Number(二分+数位dp)
题目传送门 B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 【SPOJ 1182】 SORTBIT - Sorted bit squence (数位DP)
SORTBIT - Sorted bit squence no tags Let's consider the 32 bit representation of all integers i from ...
- UVALive 4877 Non-Decreasing Digits 数位DP
4877 Non-Decreasing Digits A number is said to be made up ofnon-decreasing digitsif all the digits t ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
随机推荐
- 【转载】黑客内核:编写属于你的第一个Linux内核模块
黑客内核:编写属于你的第一个Linux内核模块
- Could not connect to SMTP host: localhost, port: 25;
1.错误描写叙述 DEBUG: setDebug: JavaMail version 1.3.3 DEBUG: getProvider() returning javax.mail.Provider[ ...
- hiho模拟面试题2 补提交卡 (贪心,枚举)
题目: 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描写叙述 小Ho给自己定了一个雄伟的目标:连续100天每天坚持在hihoCoder上提交一个程序.100天过去了.小Ho查 ...
- Zorka监控平台的Online reconfiguration基本效果展示
在上一篇日志中,我简介了Zorka的Online reconfiguration的用法,可是没怎么介绍如何看到在线更改的效果,这里简单说说. 还是以之前的tomcat为例,我们在文件夹zorka\sc ...
- bzoj1218: [HNOI2003]激光炸弹(DP二维前缀和)
1218: [HNOI2003]激光炸弹 题目:传送门 题解: 一道经典题目啊... 为了更好的操作...把整个坐标系向右上角移动,从(1,1)开始 那么f[i][j]统计一下以(i,j)作为右上角, ...
- Javascript防冒泡事件与Event对象
防冒泡 防冒泡用到的就是event的属性和方法 function add2shop(e) { if (!e) var e = window.event; e.cancelBubble = true; ...
- 不仅仅是Google,您必须知道的全球十大地图API
不仅仅是Google,您必须知道的全球十大地图API 一.总结 一句话总结:除了google,也有其它很多很好的地图,必应地图(Bing Maps),OpenLayers 二.不仅仅是Google,您 ...
- MLPclassifier,MLP 多层感知器的的缩写(Multi-layer Perceptron)
先看代码(sklearn的示例代码): from sklearn.neural_network import MLPClassifier X = [[0., 0.], [1., 1.]] y = [0 ...
- xmanager使用
Xmanager全称Netsarang Xmanager,是国外一套非常优秀的远程监控软件.在UNIX/Linux和Windows网络环境中,Xmanager是最好的连通解决方案.我推 荐大家下载En ...
- MyBatis数据持久化(七)多表连接查询
本节继续以多表连接查询的案例介绍使用resultMap的好处,对于两张以上的表进行关联查询,当我们有选择的从不同表查询所需字段时,使用resultMap是相当方便的.例如我们有两张表,分别为用户表Us ...