题目地址

一个整数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的更多相关文章

  1. BZOJ CF388D. Fox and Perfect Sets [线性基 数位DP]

    CF388D. Fox and Perfect Sets 题意:求最大元素\(le n\)的线性空间的个数 给神题跪了 orz 容易想到 每个线性基对应唯一的线性空间,我们可以统计满足条件的对应空间不 ...

  2. 【做题】CF388D. Fox and Perfect Sets——线性基&数位dp

    原文链接https://www.cnblogs.com/cly-none/p/9711279.html 题意:求有多少个非空集合\(S \subset N\)满足,\(\forall a,b \in ...

  3. Codeforces 388 D. Fox and Perfect Sets

    $ >Codeforces \space 388 D.  Fox and Perfect Sets<$ 题目大意 : 定义一个完美的集合 \(S\) ,当且仅当 \(S\) 非负非空,且 ...

  4. codeforces 388D Fox and Perfect Sets(线性基+数位dp)

    #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mp mak ...

  5. Codeforces 388D Fox and Perfect Sets

    链接:CF388D 题目大意 给定一个数\(n\),求选择\(0 \sim n\)中任意个数的数字组成的集合\(S\)中,有多少满足若\(a\in S,b\in S\),则\(a \bigoplus ...

  6. 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 ...

  7. 【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 ...

  8. 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 ...

  9. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

随机推荐

  1. SpringBoot2.0中使用订阅redis的多个频道的消息

    声明:参考文章:https://blog.csdn.net/myNameIssls/article/details/75471012?locationNum=2&fps=1 一·使用maven ...

  2. HTML5与后台服务器的数据流动问题

    编辑中,尚未完稿...2017.7.14 1345 很多前端开发出来的HTML5可能对于后台开发者来说,并不是很清楚,也许像我一样一知半解.而且真的让人很糊涂的地方就是前端的JS如何与后端的数据库进行 ...

  3. css样式中@import引入样式

    css样式中@import引入样式 学习了:http://www.cnblogs.com/zbo/archive/2010/11/17/1879590.html

  4. Coding上部署Ghost博客

    Ghost构建于Node.js平台之上.支持0.10.*版本号的Node.js. 在你的本地计算机上执行Ghost事实上非常easy,前提是你已经安装了Node.js. 什么是Node.js? 略过 ...

  5. 2 怎样解析XML文件或字符串

    1 引用XML文件 2 使用XMLReader解析文本字符串 3 使用XMLReader方法读取XML数据 详细代码实现例如以下: //初始化一个XML字符串 String xmlString = @ ...

  6. 【笨木头Lua专栏】基础补充02:函数的几个特别之处

    没想到距离上一篇基础补充已经过了1年多了,近期准备捡回Lua,把基础都补补,今天来聊聊Lua的函数吧~ 0.环境 我突然对Lua又大感兴趣的最主要原因是,Cocos Code IDE開始浮出水面了,它 ...

  7. js中cookie的使用 以及缺点

      什么是Cookie Cookie意为“甜饼”,是由W3C组织提出,最早由Netscape社区发展的一种机制.目前Cookie已经成为标准,所有的主流浏览器如IE.Netscape.Firefox. ...

  8. jQuery ajax在IE浏览器的跨域问题--jquery.xdomainrequest.min.js

    jquery.ajax 加载数据, chrome, firefox, IE10+ 都可以顺利加载数据,但是IE9及以后版本不执,通过执行 jquery.ajax error 函数显示未执行 拒绝访问. ...

  9. 【算法】单源最短路径和任意两点最短路径总结(补增:SPFA)

    [Bellman-Ford算法] [算法]Bellman-Ford算法(单源最短路径问题)(判断负圈) 结构: #define MAX_V 10000 #define MAX_E 50000 int ...

  10. bat脚本启动exe并打开文件后退出 + 中文乱码

    写了个脚本用于复制模板到新的cpp文件. 将脚本路径加到环境变量里,只需在cmd窗口输入“new hdu 1419”,就会自动将模板拷贝到WORK_DIR下的hdu文件夹内一个名叫"1419 ...