数位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 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
随机推荐
- dbgview
这两天在看一个问题,matlab打不开摄像头,总是报错. 尝试抓包,打印,分析代码,一直没有找出问题,后来用dbgview打印出来调试信息,找到了问题点. 不得不说,这个工具真不错,以前从来不知道. ...
- 实现双向数据绑定mvvm
实现双向数据绑定mvvm
- CSS解决ul下面最后一个li的margin
1.运用css3的nth-child(3n): <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...
- IE9以下版本兼容h5标签
随着html5(后面用h5代表)标签越来越广泛的使用,IE9以下(IE6-IE8)不识别h5标签的问题让人很是烦恼. 在火狐和chrome之类的浏览器中,遇到不认识的标签,只要给个display:bl ...
- 记一次BootStrap的使用
效果图如下: 一.简介: 什么是Bootstrap? Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架. 什么是响应式布局? 引用一句Bootstrap的标题语 “Boots ...
- C#-常用对象-思维导图
C#-常用对象-思维导图 链接:http://pan.baidu.com/s/1jHNgS78 密码:3i74 如有错误,请告知我!
- jQuery中focusin()和focus()、find()和children()的差别
jQuery中focus()和focusin().focus()和children()的差别 focus()和focusin() focus()和focusin()的差别在于focusin()支持事件 ...
- PHP的curl库代码使用
欢迎訪问个人原创地址: http://www.phpthinking.com/archives/468 使用PHP的cURL库能够简单和有效地去抓网页. 你仅仅须要执行一个脚本.然后分析一下你所抓取的 ...
- mybatis的sql中使用$会出现sql注入示例
mybatis的sql中使用$会出现sql注入示例: 模拟简单登录场景: 页面代码: function login(){ //sql注入 var user = { username : "' ...
- latex简历遇到的问题
博一时候简历就没弄出来,现在又要用了,于是找出当初的模板.发现问题在于编码. \XeTeXinputencoding "GBK" \XeTeXdefaultencoding &qu ...