bzoj 3209 bzoj1799 数位dp
3209: 花神的数论题
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 2267 Solved: 1040
[Submit][Status][Discuss]
Description
背景
众所周知,花神多年来凭借无边的神力狂虐各大 OJ、OI、CF、TC …… 当然也包括 CH 啦。
描述
话说花神这天又来讲课了。课后照例有超级难的神题啦…… 我等蒟蒻又遭殃了。
花神的题目是这样的
设 sum(i) 表示 i 的二进制表示中 1 的个数。给出一个正整数 N ,花神要问你
派(Sum(i)),也就是 sum(1)—sum(N) 的乘积。
Input
一个正整数 N。
Output
一个数,答案模 10000007 的值。
Sample Input
3
Sample Output
2
HINT
对于样例一,1*1*2=2;
数据范围与约定
对于 100% 的数据,N≤10^15
- // 数位dp模板题 10^15最多52个1,枚举1的个数来统计就行了。
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- using namespace std;
- typedef long long ll;
- const ll mod=1e7+;
- int bit[],maxv;
- ll dp[][];
- ll pow_mod(ll a,ll b)
- {
- if(b==) return ;
- ll x=pow_mod(a,b/);
- ll ans=x*x%mod;
- if(b&) ans=ans*a%mod;
- return ans;
- }
- ll dfs(int pos,int x,int limt)
- {
- if(pos<=) return x==maxv;
- if(!limt&&dp[pos][x]!=-) return dp[pos][x];
- ll ans=;
- int maxb=(limt?bit[pos]:);
- for(int i=;i<=maxb;i++){
- ans+=dfs(pos-,x+i,limt&&(i==maxb));
- }
- if(!limt) dp[pos][x]=ans;
- return ans;
- }
- void solve(ll n)
- {
- int nu=;
- while(n){
- bit[++nu]=(n&);
- n>>=;
- }
- ll ans=;
- for(int i=;i<=nu;i++){
- memset(dp,-,sizeof(dp));
- maxv=i;
- ll tmp=dfs(nu,,);
- ans=ans*pow_mod(i,tmp)%mod;
- }
- printf("%lld\n",ans);
- }
- int main()
- {
- ll n;
- scanf("%lld",&n);
- solve(n);
- return ;
- }
1799: [Ahoi2009]self 同类分布
Time Limit: 50 Sec Memory Limit: 64 MB
Submit: 1245 Solved: 535
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
Sample Output
HINT
【约束条件】1 ≤ a ≤ b ≤ 10^18
- //数位dp模板题 10^18的数数位和最大是153,然后枚举数位和然后就行了。刚开始还傻到想要求前153个数的lcm。。。。
- //dfs时记录余数pre 和数位和sum。
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- using namespace std;
- typedef long long ll;
- ll dp[][][],po[];
- int bit[];
- ll dfs(int pos,int mod,int sum,int pre,bool w){
- if(pos<=) return pre==&&sum==mod;
- if(!w&&dp[pos][sum][pre]!=-) return dp[pos][sum][pre];
- ll ans=;
- int maxb=(w?bit[pos]:);
- for(int i=;i<=maxb;i++){
- ans+=dfs(pos-,mod,sum+i,(pre+i*po[pos])%mod,w&&(i==maxb));
- }
- if(!w) dp[pos][sum][pre]=ans;
- return ans;
- }
- ll solve(ll x)
- {
- int nu=;
- while(x){
- bit[++nu]=x%;
- x/=;
- }
- ll ans=;
- for(int mod=;mod<=nu*;mod++){
- memset(dp,-,sizeof(dp));
- ans+=dfs(nu,mod,,,);
- }
- return ans;
- }
- int main()
- {
- po[]=;
- for(int i=;i<=;i++) po[i]=po[i-]*1LL*;
- ll a,b;
- scanf("%lld%lld",&a,&b);
- printf("%lld\n",solve(b)-solve(a-));
- return ;
- }
bzoj 3209 bzoj1799 数位dp的更多相关文章
- BZOJ 3329: Xorequ [数位DP 矩阵乘法]
3329: Xorequ 题意:\(\le n \le 10^18\)和\(\le 2^n\)中满足\(x\oplus 3x = 2x\)的解的个数,第二问模1e9+7 \(x\oplus 2x = ...
- BZOJ.3329.Xorequ(数位DP)
题目链接 x^3x=2x -> x^2x=3x 因为a^b+((a&b)<<1)=a+b,x^2x=x+2x,所以x和2x的二进制表示中不存在相邻的1. (或者,因为x+2x ...
- BZOJ 3329 - Xorequ - 数位DP, 矩乘
Solution 发现 $x \ xor \ 2x = 3x$ 仅当 $x$ 的二进制中没有相邻的 $1$ 对于第一个问题就可以进行数位DP 了. 但是对于第二个问题, 我们只能通过递推 打表 来算 ...
- BZOJ 3329 Xorequ (数位DP、矩阵乘法)
手动博客搬家: 本文发表于20181105 23:18:54, 原地址https://blog.csdn.net/suncongbo/article/details/83758728 题目链接 htt ...
- BZOJ 3329: Xorequ(数位dp+递推)
传送门 解题思路 可以把原式移项得\(x\)^\(2x\)=\(3x\),而\(x+2x=3x\),说明\(x\)二进制下不能有两个连续的\(1\).那么第一问就是一个简单的数位\(dp\),第二问考 ...
- BZOJ 3209: 花神的数论题 [数位DP]
3209: 花神的数论题 题意:求\(1到n\le 10^{15}\)二进制1的个数的乘积,取模1e7+7 二进制最多50位,我们统计每种1的个数的数的个数,快速幂再乘起来就行了 裸数位DP..\(f ...
- bzoj 3209 花神的数论题 —— 数位DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3209 算是挺简单的数位DP吧,但还是花了好久才弄明白... 又参考了博客:https://b ...
- bzoj 3209 花神的数论题——二进制下的数位dp
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3209 可以枚举 “1的个数是...的数有多少个” ,然后就是用组合数算在多少位里选几个1. ...
- BZOJ 3209 花神的数论题 数位DP+数论
题目大意:令Sum(i)为i在二进制下1的个数 求∏(1<=i<=n)Sum(i) 一道非常easy的数位DP 首先我们打表打出组合数 然后利用数位DP统计出二进制下1的个数为x的数的数量 ...
随机推荐
- Paper Reading - Long-term Recurrent Convolutional Networks for Visual Recognition and Description ( CVPR 2015 )
Link of the Paper: https://arxiv.org/abs/1411.4389 Main Points: A novel Recurrent Convolutional Arch ...
- 微软职位内部推荐-SW Engineer II for Windows System
微软近期Open的职位: Microsoft's Operating Systems Group delivers the operating system and core user experie ...
- Scrum立会报告+燃尽图(Beta阶段第二周第四次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2412 项目地址:https://coding.net/u/wuyy694 ...
- 安装cocoa pods
1.移除现有Ruby默认源 $gem sources --remove https://rubygems.org/ 2.使用新的源 $gem sources -a https://ruby.taoba ...
- web项目页面加载时,下拉框有值
1.我用的框架是springmvc和mybaitis 由于没有整个项目,直接就去请求的action :http://localhost:8080/ytert/test/selectStoreType ...
- android入门 — Activity生命周期
Activity总共有7个回调方法,代表着不同的生命周期的环节. 1.onCreate() 在活动第一次被创建的时候调用.在这个方法中需要完成活动的初始化操作,比如说加载布局.绑定事件等. 2.onS ...
- alpha发布评论
飞天小女警我们自己的礼物挑选工具完整度不高,页面简陋,还有很多需要完善和改进的地方,空间比较大,但是本身能力太不足. 个人比较喜欢奋斗吧兄弟做的食物链系统.感觉是可以拿来用的工具吧. 天天向上的游戏连 ...
- selenium webdriver 表格的定位方法练习
selenium webdriver 表格的定位方法 html 数据准备 <html> <body> <div id="div1"> <i ...
- [cnbeta]微软最强数据中心级操作系统
微软近日发表了一篇介绍Windows系统内核的博文,期间为了展示Windows的强大扩展性,放出了一张非常震撼的Windows任务管理器截图:乍一看似乎没啥特别的,几十甚至上百个逻辑核心的系统并不罕见 ...
- libmnl
https://www.netfilter.org/projects/libmnl/doxygen/modules.html 1,tar xvf libmnl-1.0.4.tar.gz 2,cd li ...