codeforces 388D Fox and Perfect Sets(线性基+数位dp)
#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)的更多相关文章
- 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 388D Fox and Perfect Sets
链接:CF388D 题目大意 给定一个数\(n\),求选择\(0 \sim n\)中任意个数的数字组成的集合\(S\)中,有多少满足若\(a\in S,b\in S\),则\(a \bigoplus ...
- Codeforces 1299D - Around the World(线性基+图论+dp)
Codeforces 题目传送门 & 洛谷题目传送门 一道线性基的综合题 %%%%%% 首先注意到"非简单路径""异或和"等字眼,可以本能地想到线性基. ...
- Codeforces 388 D. Fox and Perfect Sets
$ >Codeforces \space 388 D. Fox and Perfect Sets<$ 题目大意 : 定义一个完美的集合 \(S\) ,当且仅当 \(S\) 非负非空,且 ...
- Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理
https://codeforces.com/contest/1100/problem/F 题意 一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和 题解 单问区间子集最大异或和,线性基 ...
- 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 ...
- bzoj 3811: 玛里苟斯【线性基+期望dp】
这个输出可是有点恶心啊--WA*inf,最后抄了别人的输出方法orz 还有注意会爆long long,要开unsigned long long 对于k==1,单独考虑每一位i,如果这一位为1则有0.5 ...
- 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 ...
随机推荐
- cnblog博客停用
本博客从今日起停止更新,后续的文章将会发布在新的博客mrbackkom.github.io
- JAVA 方法 和Scanner
方法:包含于类或对象中,是解决一类问题步骤的有序组合. 算法:解决一类问题的思想. Scanner next()与nextLine()区别 next(): 1.一定要读取到有效字符后才可以结束输入. ...
- WinForm-SuspendLayout、ResumeLayout、PerformLayou——转载
WinForm-SuspendLayout.ResumeLayout.PerformLayou——转载 https://www.cnblogs.com/si-shaohua/archive/2011/ ...
- 什么是SSH
SSH不仅实现了视图.控制器与模型的彻底分离,而且还实现了业务逻辑层与持久层的分离,耦合度降低,系统的灵活性更好,可复用性高 官方的说法:SSH是 struts+spring+hibernate的一个 ...
- SmartGit破解使用的个人方法
转自:https://www.cnblogs.com/nn839155963/p/5912788.html SmartGit是收费的,可以30天的试用期,30天试用期过后,smartgit 需要输入序 ...
- mongo_connector.oplog_manager:670 - Exception during collection dump
今天再整合mongodb和elasticsearch时,执行最后一步命令 “mongo-connector -m -m localhost:8090 -t -t -t localhost:9200 ...
- XML文档的解析—dom4j
XML为可扩展标记语言,它主要是用来保存数据,做配置文件,数据传输载体等.其实就是一个后缀名为.xml的文件. XML命名规则 名称可以含字母.数字以及其他的字符 名称不能以数字或者标点符号开始 名称 ...
- JavaMail获取已发送邮件
public static void main(String args[]) { Properties props = new Properties(); // 参数配置 props.setPrope ...
- Spring入门(三)— AOP注解、jdbc模板、事务
一.AOP注解开发 导入jar包 aop联盟包. aspectJ实现包 . spring-aop-xxx.jar . spring-aspect-xxx.jar 导入约束 aop约束 托管扩展类和被扩 ...
- RegExp使用技巧
正则表达式 //用法 1. /\d/g 2. new RegExp('/\d/','g') //修饰符 g,i,m //元字符 1.元字符是在正则表达式中有特殊含义的非字母字符 . * + ? $ ^ ...