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 ...
随机推荐
- 再回首:object是什么
前言 这里说得object是C#语言中的类型object,也是Framework中的System.Object(两者是一个意思).如其名“面向对象编程”对象就是Object.既然提到面向对象,自然就想 ...
- JDK1.7新特性(4):java语言动态性之反射API
直接通过一个代码示例来熟悉java中通过反射来对构造函数/域以及方法处理的相关API: package com.rampage.jdk7.chapter2; import java.lang.refl ...
- nodejs学习笔记一( sublime、atom开发环境,http模块,fs模块的初识)
http服务 let server = http.createServer(function(req,res){ }); 监听: server.listen(8080); re ...
- [转]Calling an OData Service From a .NET Client (C#)
本文转自:https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata- ...
- SQL Serever学习7——数据表2
修改数据表的属性 保存数据表的修改的时候,总会弹出阻止修改的警告. 解决方法2种: 1.可以使用T-sql语句强行修改 2.工具>选项>设计器>表设计器和数据库设计器>阻止保存 ...
- <深入理解JavaScript>学习笔记(2)_揭秘命名函数表达式
写在前面的话 注:本文是拜读了 深入理解JavaScript 之后深有感悟,故做次笔记方便之后查看. 感觉这章的内容有点深奥....略难懂啊. 先坐下笔记,加深一下印象吧. 我主要记一下自己感觉有用的 ...
- 【12】FtpWebRequest上传下载
下载文件 /// <summary> /// 下载文件 /// </summary> /// <param name="filename">&l ...
- KnockoutJS Select 标签 Options绑定
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- SmartGit破解使用的个人方法
转自:https://www.cnblogs.com/nn839155963/p/5912788.html SmartGit是收费的,可以30天的试用期,30天试用期过后,smartgit 需要输入序 ...
- mongdb启动报错
2018-08-19T12:25:31.707+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1 ...