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 ...
随机推荐
- 端口扫描工具nmap
nmap 使用介绍 nmap是目前为止最广为使用的国外端口扫描工具之一.我们可以从[url]http://www.insecure.org/[/url]进行下载,可以很容易的安装到Windows和un ...
- 工作中遇到的一道SQL应用题
登录日志表 CREATE TABLE [dbo].[LoginLog]([Seq] [int] NOT NULL IDENTITY(1, 1), --Seq[UserId] [varchar] (2 ...
- 撩课-Web大前端每天5道面试题-Day9
1. 请用至少3中方式实现数组去重? 方法一: indexOf ,,,,,,,,]; function repeat1(arr){ ,arr2=[];i<arr.length;i++){ ){ ...
- HDU3629:Convex
传送门 求凸四边形的个数 转化成总数减去凹四边形的个数 凹四边形一定是一个三角形中间包含的另外一个点 那么枚举被包含的点,其它的对于这个点极角排序 被包含不好算,算总数减去不被包含的 枚举三角形的一个 ...
- UOJ#316. 【NOI2017】泳池
传送门 一道 \(DP\) 好题 设 \(q\) 为一个块合法的概率 套路一恰好为 \(k\) 的概率不好算,算小于等于 \(k\) 的减去小于等于 \(k-1\) 的 那么设 \(f_i\) 表示宽 ...
- websocket协议及案例
WebSocket是一种用于在服务器与客户端之间实现高效的双向通信的机制.可以解决数据实时性要求比较高的应用,比如:在线聊天,在线教育,炒股或定位等. 一:websocket产生背景: 为了解决这种实 ...
- C#编写强大的SQL Server数据库自动备份服务
数据库自动备份服务,带配置,还算可以吧 周末抽时间,编写了一个这样的工具,可以让,对数据库不了解或不熟悉的人,直接学会使用备份,省时省力,同样,我也将一份,通过脚本进行备份的,也奉献上来, 通过sql ...
- 【javascript】javascript设计模式mixin模式
概述: Mixin是JavaScript中用的最普遍的模式,几乎所有流行类库都会有Mixin的实现.任意一个对象的全部或部分属性拷贝到另一个对象上. 一 .混合对象 二 .混合类
- Visual Studio Code 保存时自动格式化的问题
烦人的说,保存的时候自动格式化, 格式话后,代码就失效了 纳尼!!!! 网上其他人都说 JS-CSS-HTML Formatter这个插件在捣蛋! 试了,的确如此. 找到他,给禁用,就不会 ...
- 微信小程序开发11-HTTPS网络通信(重点)
1.OneNET平台支持https,将HTTP头部改成https://api.heclouds.com即可(重点!!!!!!!!) 2.如果我们需要从 https://test.com/getinfo ...