题意:给定x、y。为[x,y]之间有多少个数的偶数位和减去奇数位和等于一。

个位是第一位。

样例: 10=1-0=1 所以10是这种数

思路:数位dp[i][sum][ok] i位和为sum 是否含有前导0.

然后就是由于有负数 所以依据范围把0设置为100 然后最后和等于101则为所求的数。

代码:

  1. #include"cstdlib"
  2. #include"cstdio"
  3. #include"cstring"
  4. #include"cmath"
  5. #include"stack"
  6. #include"algorithm"
  7. #include"iostream"
  8. using namespace std;
  9. int dp[12][200][2],num[12];
  10. int fuck[2]={1,-1};
  11. int dfs(int site,int sum,int ok,int f)
  12. {
  13. if(site==0)
  14. {
  15. if(ok==0) return 0;
  16. return sum==101?1:0; //小处理 和为101
  17. }
  18. if(!f&&dp[site][sum][ok]!=-1) return dp[site][sum][ok];
  19. int len=f?num[site]:9;
  20. int ans=0;
  21. for(int i=0;i<=len;i++)
  22. {
  23. if(ok==0)
  24. {
  25. if(i==0) ans+=dfs(site-1,sum,ok||i!=0,f&&i==len);
  26. else ans+=dfs(site-1,sum+i*fuck[site%2],ok||i!=0,f&&i==len);
  27. }
  28. else
  29. {
  30. ans+=dfs(site-1,sum+i*fuck[site%2],ok||i!=0,f&&i==len);
  31. }
  32. }
  33. if(!f) dp[site][sum][ok]=ans;
  34. return ans;
  35. }
  36. int solve(int x)
  37. {
  38. if(x<0) return 0;
  39. int cnt=0;
  40. while(x)
  41. {
  42. num[++cnt]=x%10;
  43. x/=10;
  44. }
  45. return dfs(cnt,100,0,1); //进入的时候 sum=100
  46. }
  47. int main()
  48. {
  49. int t;
  50. scanf("%d",&t);
  51. memset(dp,-1,sizeof(dp));
  52. while(t--)
  53. {
  54. int x,y;
  55. scanf("%d%d",&x,&y);
  56. printf("%d\n",solve(y)-solve(x-1));
  57. }
  58. return 0;
  59. }

[数位dp] spoj 10738 Ra-One Numbers的更多相关文章

  1. 【数位dp】CF 55D Beautiful numbers

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

  2. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

  3. SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]

    题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...

  4. SPOJ BALNUM Balanced Numbers (数位dp)

    题目:http://www.spoj.com/problems/BALNUM/en/ 题意:找出区间[A, B]内所有奇数字出现次数为偶数,偶数字出现次数为计数的数的个数. 分析: 明显的数位dp题, ...

  5. 【SPOJ 2319】 BIGSEQ - Sequence (数位DP+高精度)

    BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need ...

  6. 【SPOJ 1182】 SORTBIT - Sorted bit squence (数位DP)

    SORTBIT - Sorted bit squence no tags Let's consider the 32 bit representation of all integers i from ...

  7. Balanced Numbers (数位dp+三进制)

    SPOJ - BALNUM 题意: Balanced Numbers:数位上的偶数出现奇数次,数位上的奇数出现偶数次(比如2334, 2出现1次,4出现1次,3出现两次,所以2334是 Balance ...

  8. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  9. 找规律/数位DP HDOJ 4722 Good Numbers

    题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...

随机推荐

  1. Java程序员如何选择未来的职业路线

    一.程序员的特性 技术出身的职场人特性很明显,与做市场.业务出身的职场人区别尤其明显.IT行业中常见的一些职场角色:老板.项目经理.产品经理.需求分析师.设计师.开发工程师.运维工程师等.开发工程师具 ...

  2. Number Sequence kmp

    Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...

  3. Python图表数据可视化Seaborn:1. 风格| 分布数据可视化-直方图| 密度图| 散点图

    conda  install seaborn  是安装到jupyter那个环境的 1. 整体风格设置 对图表整体颜色.比例等进行风格设置,包括颜色色板等调用系统风格进行数据可视化 set() / se ...

  4. 20165235 祁瑛 2018-4 《Java程序设计》第六周学习总结

    20165235 祁瑛 2018-4 <Java程序设计>第六周学习总结 教材学习内容总结 常用实用类 (一)1.String类是final类型的,String类型常量也是对象.2.可以使 ...

  5. Spring Security(15)——权限鉴定结构 RoleVoter

    http://www.cnblogs.com/fenglan/p/5913432.html

  6. java日志的相关配置文件知识

    w2bc.com/article/261758”“”“

  7. Python操纵Excel,数据库

    操作excelxlwt:写入excel表格 ,用这个之前需要先导入模块 xlwt: import xlwtxlrd:读取excel,用这个之前需要先导入模块 xlwt:import xlrd 注意:e ...

  8. 直接引用vee-validate校验插件

    直接在页面引用vee-validate 源文件下载地址:http://www.bootcdn.cn/vee-validate/ 官方api https://baianat.github.io/vee- ...

  9. oracle中两个时间类型的数据相减默认得到的是天数。

    想要得到月份数,需要使用months_between函数. months_between(to_date('201707','yyyyMM'),to_date('201706','yyyyMM'))  ...

  10. linux下执行.sh文件的方法和语法

    linux下执行.sh文件的方法    .sh文件就是文本文件,如果要执行,需要使用chmod a+x xxx.sh来给可执行权限.       是bash脚本么   可以用touch test.sh ...