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

  1. // 数位dp模板题 10^15最多52个1,枚举1的个数来统计就行了。
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. using namespace std;
  6. typedef long long ll;
  7. const ll mod=1e7+;
  8. int bit[],maxv;
  9. ll dp[][];
  10. ll pow_mod(ll a,ll b)
  11. {
  12. if(b==) return ;
  13. ll x=pow_mod(a,b/);
  14. ll ans=x*x%mod;
  15. if(b&) ans=ans*a%mod;
  16. return ans;
  17. }
  18. ll dfs(int pos,int x,int limt)
  19. {
  20. if(pos<=) return x==maxv;
  21. if(!limt&&dp[pos][x]!=-) return dp[pos][x];
  22. ll ans=;
  23. int maxb=(limt?bit[pos]:);
  24. for(int i=;i<=maxb;i++){
  25. ans+=dfs(pos-,x+i,limt&&(i==maxb));
  26. }
  27. if(!limt) dp[pos][x]=ans;
  28. return ans;
  29. }
  30. void solve(ll n)
  31. {
  32. int nu=;
  33. while(n){
  34. bit[++nu]=(n&);
  35. n>>=;
  36. }
  37. ll ans=;
  38. for(int i=;i<=nu;i++){
  39. memset(dp,-,sizeof(dp));
  40. maxv=i;
  41. ll tmp=dfs(nu,,);
  42. ans=ans*pow_mod(i,tmp)%mod;
  43. }
  44. printf("%lld\n",ans);
  45. }
  46. int main()
  47. {
  48. ll n;
  49. scanf("%lld",&n);
  50. solve(n);
  51. return ;
  52. }

1799: [Ahoi2009]self 同类分布

Time Limit: 50 Sec  Memory Limit: 64 MB
Submit: 1245  Solved: 535
[Submit][Status][Discuss]

Description

给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数。

Input

 

Output

 

Sample Input

10 19

Sample Output

3

HINT

【约束条件】1 ≤ a ≤ b ≤ 10^18

代码:
  1. //数位dp模板题 10^18的数数位和最大是153,然后枚举数位和然后就行了。刚开始还傻到想要求前153个数的lcm。。。。
  2. //dfs时记录余数pre 和数位和sum。
  3. #include<iostream>
  4. #include<cstdio>
  5. #include<cstring>
  6. using namespace std;
  7. typedef long long ll;
  8. ll dp[][][],po[];
  9. int bit[];
  10. ll dfs(int pos,int mod,int sum,int pre,bool w){
  11. if(pos<=) return pre==&&sum==mod;
  12. if(!w&&dp[pos][sum][pre]!=-) return dp[pos][sum][pre];
  13. ll ans=;
  14. int maxb=(w?bit[pos]:);
  15. for(int i=;i<=maxb;i++){
  16. ans+=dfs(pos-,mod,sum+i,(pre+i*po[pos])%mod,w&&(i==maxb));
  17. }
  18. if(!w) dp[pos][sum][pre]=ans;
  19. return ans;
  20. }
  21. ll solve(ll x)
  22. {
  23. int nu=;
  24. while(x){
  25. bit[++nu]=x%;
  26. x/=;
  27. }
  28. ll ans=;
  29. for(int mod=;mod<=nu*;mod++){
  30. memset(dp,-,sizeof(dp));
  31. ans+=dfs(nu,mod,,,);
  32. }
  33. return ans;
  34. }
  35. int main()
  36. {
  37. po[]=;
  38. for(int i=;i<=;i++) po[i]=po[i-]*1LL*;
  39. ll a,b;
  40. scanf("%lld%lld",&a,&b);
  41. printf("%lld\n",solve(b)-solve(a-));
  42. return ;
  43. }

bzoj 3209 bzoj1799 数位dp的更多相关文章

  1. BZOJ 3329: Xorequ [数位DP 矩阵乘法]

    3329: Xorequ 题意:\(\le n \le 10^18\)和\(\le 2^n\)中满足\(x\oplus 3x = 2x\)的解的个数,第二问模1e9+7 \(x\oplus 2x = ...

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

  3. BZOJ 3329 - Xorequ - 数位DP, 矩乘

    Solution 发现 $x \ xor \  2x = 3x$ 仅当 $x$ 的二进制中没有相邻的 $1$ 对于第一个问题就可以进行数位DP 了. 但是对于第二个问题, 我们只能通过递推 打表 来算 ...

  4. BZOJ 3329 Xorequ (数位DP、矩阵乘法)

    手动博客搬家: 本文发表于20181105 23:18:54, 原地址https://blog.csdn.net/suncongbo/article/details/83758728 题目链接 htt ...

  5. BZOJ 3329: Xorequ(数位dp+递推)

    传送门 解题思路 可以把原式移项得\(x\)^\(2x\)=\(3x\),而\(x+2x=3x\),说明\(x\)二进制下不能有两个连续的\(1\).那么第一问就是一个简单的数位\(dp\),第二问考 ...

  6. BZOJ 3209: 花神的数论题 [数位DP]

    3209: 花神的数论题 题意:求\(1到n\le 10^{15}\)二进制1的个数的乘积,取模1e7+7 二进制最多50位,我们统计每种1的个数的数的个数,快速幂再乘起来就行了 裸数位DP..\(f ...

  7. bzoj 3209 花神的数论题 —— 数位DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3209 算是挺简单的数位DP吧,但还是花了好久才弄明白... 又参考了博客:https://b ...

  8. bzoj 3209 花神的数论题——二进制下的数位dp

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3209 可以枚举 “1的个数是...的数有多少个” ,然后就是用组合数算在多少位里选几个1. ...

  9. BZOJ 3209 花神的数论题 数位DP+数论

    题目大意:令Sum(i)为i在二进制下1的个数 求∏(1<=i<=n)Sum(i) 一道非常easy的数位DP 首先我们打表打出组合数 然后利用数位DP统计出二进制下1的个数为x的数的数量 ...

随机推荐

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

  2. 微软职位内部推荐-SW Engineer II for Windows System

    微软近期Open的职位: Microsoft's Operating Systems Group delivers the operating system and core user experie ...

  3. Scrum立会报告+燃尽图(Beta阶段第二周第四次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2412 项目地址:https://coding.net/u/wuyy694 ...

  4. 安装cocoa pods

    1.移除现有Ruby默认源 $gem sources --remove https://rubygems.org/ 2.使用新的源 $gem sources -a https://ruby.taoba ...

  5. web项目页面加载时,下拉框有值

    1.我用的框架是springmvc和mybaitis 由于没有整个项目,直接就去请求的action  :http://localhost:8080/ytert/test/selectStoreType ...

  6. android入门 — Activity生命周期

    Activity总共有7个回调方法,代表着不同的生命周期的环节. 1.onCreate() 在活动第一次被创建的时候调用.在这个方法中需要完成活动的初始化操作,比如说加载布局.绑定事件等. 2.onS ...

  7. alpha发布评论

    飞天小女警我们自己的礼物挑选工具完整度不高,页面简陋,还有很多需要完善和改进的地方,空间比较大,但是本身能力太不足. 个人比较喜欢奋斗吧兄弟做的食物链系统.感觉是可以拿来用的工具吧. 天天向上的游戏连 ...

  8. selenium webdriver 表格的定位方法练习

    selenium webdriver 表格的定位方法 html 数据准备 <html> <body> <div id="div1"> <i ...

  9. [cnbeta]微软最强数据中心级操作系统

    微软近日发表了一篇介绍Windows系统内核的博文,期间为了展示Windows的强大扩展性,放出了一张非常震撼的Windows任务管理器截图:乍一看似乎没啥特别的,几十甚至上百个逻辑核心的系统并不罕见 ...

  10. libmnl

    https://www.netfilter.org/projects/libmnl/doxygen/modules.html 1,tar xvf libmnl-1.0.4.tar.gz 2,cd li ...