#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(x) (int)x.size()
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi; const int P=1e9+7;
int n, k;
int a[33];
ll f[33][33][2], pw[33]; void upd(ll &a, ll b) {
a+=b;
if(a>=P) a-=P;
}
void init() {
pw[0]=1;
rep(i,1,33) pw[i]=pw[i-1]*2%P;
} int main() {
init();
while(~scanf("%d",&k)) {
n=0;
while(k) {
a[++n]=(k&1);
k>>=1;
}
for(int l=1, r=n;l<r;++l, --r) swap(a[l], a[r]);
memset(f,0,sizeof(f));
f[0][0][1]=1;
rep(i,0,n) rep(j,0,i+1) {
if(f[i][j][0]) {
upd(f[i+1][j+1][0], f[i][j][0]);
upd(f[i+1][j][0], f[i][j][0]*pw[j]%P);
}
if(f[i][j][1]) {
if(a[i+1]) upd(f[i+1][j+1][1], f[i][j][1]);
if(a[i+1]) upd(f[i+1][j][0], f[i][j][1]*(j?pw[j-1]:1)%P);
upd(f[i+1][j][1], f[i][j][1]*(j?pw[j-1]:0)%P);
}
}
ll ans=0;
rep(i,0,n+1) rep(j,0,2) if(f[n][i][j]) {
upd(ans, f[n][i][j]);
}
printf("%lld\n",ans);
}
return 0;
}

codeforces 388D Fox and Perfect Sets(线性基+数位dp)的更多相关文章

  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 388D Fox and Perfect Sets

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

  4. Codeforces 1299D - Around the World(线性基+图论+dp)

    Codeforces 题目传送门 & 洛谷题目传送门 一道线性基的综合题 %%%%%% 首先注意到"非简单路径""异或和"等字眼,可以本能地想到线性基. ...

  5. Codeforces 388 D. Fox and Perfect Sets

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

  6. Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理

    https://codeforces.com/contest/1100/problem/F 题意 一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和 题解 单问区间子集最大异或和,线性基 ...

  7. CodeForces - 1101G :(Zero XOR Subset)-less(线性基)

    You are given an array a1,a2,…,an of integer numbers. Your task is to divide the array into the maxi ...

  8. bzoj 3811: 玛里苟斯【线性基+期望dp】

    这个输出可是有点恶心啊--WA*inf,最后抄了别人的输出方法orz 还有注意会爆long long,要开unsigned long long 对于k==1,单独考虑每一位i,如果这一位为1则有0.5 ...

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

随机推荐

  1. Wahrscheinlichkeitstheorie und mathematische Statistik

    Übliches Wort 正态分布:Die Normalverteilung 条件概率:Die Bedingte Wahrscheinlichkeit 排列:Die Permutation 组合:D ...

  2. Java泛型的逆变

    在上篇<Java泛型的协变>这篇文章中遗留以下问题——协变不能解决将子类型添加到父类型的泛型列表中.本篇将用逆变来解决这个问题. 实验准备 我们首先增加以下方法,见代码清单1所示. 代码清 ...

  3. springboot在阿里CentOS 7后台永久运行

    查看Java进程可以使用 ps -ef|grep java 首次后台永久启动,会把日志输出到新建的log.file文件 nohup java -jar demo-0.0.1-SNAPSHOT.jar ...

  4. JAVA基础之——JDK包分析concurrent

    concurrent在哪儿:jdk\jre\lib\rt.jar package java.util.concurrent; 本文从特性.分类.扩展方面一一道来. 1 特性 包中包含大量有用的构建块, ...

  5. golang rpc 简单范例

    RPC(Remote Procedure Call Protocol)--远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议. 它的工作流程如下图:   go ...

  6. jdk锁相关

    锁类型 可重入锁:在执行对象中所有同步方法不用再次获得锁 可中断锁:在等待获取锁过程中可中断 公平锁: 按等待获取锁的线程的等待时间进行获取,等待时间长的具有优先获取锁权利 读写锁:对资源读取和写入的 ...

  7. git杂记-打标签

    列出标签 $ git tag v0. v1. 创建标签 --添加附注标签(推荐):加上-a选项(annotated) $ git tag -a v1. -m 'my version 1.4' --添加 ...

  8. luogu P3065 first——trie树相关

    题目描述 Bessie has been playing with strings again. She found that by changing the order of the alphabe ...

  9. BZOJ5465: [APIO 2018] 选圆圈(K-D Tree)

    题意 题目链接 Sol 下面是错误做法,正解请看这里 考虑直接用K-D tree模拟.. 刚开始想的是维护矩形最大最小值,以及子树中最大圆的位置,然后... 实际上最大圆的位置是不用维护的,直接把原序 ...

  10. [转]web使用Quartz.NET实现作业调度

    转自 https://www.cnblogs.com/best/p/7658573.html 一.Quartz.NET介绍 Quartz.NET是一个强大.开源.轻量的作业调度框架,是 OpenSym ...