思路:搜索的时候是从高位到低位,所以一旦遇到非0数字,也就确定了数的长度,这样就知道回文串的中心点。

代码如下:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<vector>
  6. #include<cstring>
  7. #define ll long long
  8. using namespace std;
  9. ll dp[][][];
  10. int bit[],num[];
  11. ll dfs(int pos,int m,int s,bool f)
  12. {
  13. if(!pos) return ;
  14. if(!f&&dp[pos][m][s]!=-) return dp[pos][m][s];
  15. ll ans=;
  16. int e=f?bit[pos]:;
  17. for(int i=;i<=e;i++){
  18. if(!s){
  19. num[pos]=i;
  20. ans+=dfs(pos-,m-!i,s||i,f&&i==e);
  21. }
  22. else{
  23. int t=(m+)>>;
  24. bool flag=m&?pos<t:pos<=t;
  25. if(flag){
  26. if(num[m+-pos]==i)
  27. ans+=dfs(pos-,m,s,f&&i==e);
  28. }
  29. else{
  30. num[pos]=i;
  31. ans+=dfs(pos-,m,s,f&&i==e);
  32. }
  33. }
  34. }
  35. if(!f) dp[pos][m][s]=ans;
  36. return ans;
  37. }
  38. ll cal(ll n)
  39. {
  40. int m=;
  41. while(n){
  42. bit[++m]=n%;
  43. n/=;
  44. }
  45. return dfs(m,m,,);
  46. }
  47. int main()
  48. {
  49. int t,ca=;
  50. ll a,b;
  51. memset(dp,-,sizeof(dp));
  52. scanf("%d",&t);
  53. while(t--){
  54. scanf("%lld%lld",&a,&b);
  55. if(a>b) swap(a,b);
  56. printf("Case %d: %lld\n",++ca,cal(b)-cal(a-));
  57. }
  58. return ;
  59. }

light oj 1205 - Palindromic Numbers 数位DP的更多相关文章

  1. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  2. light 1205 - Palindromic Numbers(数位dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1205 题解:这题作为一个数位dp,是需要咚咚脑子想想的.这个数位dp方程可能不 ...

  3. LightOJ 1205 Palindromic Numbers

    数位DP.... Palindromic Numbers Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %l ...

  4. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  5. Codeforces Beta Round #51 D. Beautiful numbers 数位dp

    D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...

  6. poj 3252 Round Numbers(数位dp 处理前导零)

    Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...

  7. uva 10712 - Count the Numbers(数位dp)

    题目链接:uva 10712 - Count the Numbers 题目大意:给出n,a.b.问说在a到b之间有多少个n. 解题思路:数位dp.dp[i][j][x][y]表示第i位为j的时候.x是 ...

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

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

  9. SPOJ10606 BALNUM - Balanced Numbers(数位DP+状压)

    Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a ...

随机推荐

  1. jQuery选项卡插件

    html结构 <ul id="tabs" class="tabs"> <li data-tab="users">Us ...

  2. Go语言类型switch

    switch还可以用于判断变量类型.使用方式为T.(type),即在变量后加上.(type).见代码: package main import ( "fmt" ) func mai ...

  3. iOS8 蓝牙设备的重连接(retrieve) Swift实现

    今天App写到了蓝牙重连的阶段,以前针对sdk 6.0写的代码,蓝牙设备的回复是通过 - (void)retrievePeripherals:(NSArray *)peripheralUUIDs 然后 ...

  4. 在DNS管理器——用局域网IP指定你所起的域名名称

    在服务器上面,进行以下相关的操作: 第一步:打开DNS管理器; 第二步:在“正向查找区域”添加域名为:icanyin.net; 第三步:添加主机pm,将域名pm.icanyin.net解析为IP地址: ...

  5. 41.使用Chipscope时如何防止reg_wire型信号被优化掉

    随着FPGA设计复杂程度越来越高,芯片内部逻辑分析功能显得越来越重要.硬件层次上的逻辑分析仪价格十分昂贵,而且操作比较复杂.目前,FPGA芯片的两大供应商都为自己的FPGA芯片提供了软件层面上的逻辑分 ...

  6. Could not resolve placeholder

    使用spring的<context:property-placeholder location="/WEB-INF/redis.properties"/>读取prope ...

  7. gitlab&fengoffice的ldap配置

    1.fengoffice配置config/ldap_config.php $config_ldap = array ( 'binddn' => 'cn=admin,dc=xxx,dc=xxx', ...

  8. 阿里云无线&前端团队是如何基于webpack实现前端工程化的

    背景 前端经历了初期的野蛮生长(切图,写简单的特效)——为了兼容浏览器兼容性而出现的各种类库(JQUERY,YUI等——mv*(饱暖思淫欲,代码多了,也就想到怎样组织代码结构,backbone,ang ...

  9. Oracle数据库中文乱码问题

    最近碰到Oracle乱码问题,刚开始甚是头疼,以前在合肥出差的时候,这种问题也碰到过,当时直接抛给了“乌压压一片”(一个搞数据的同事儿),这次没办法躲过,只好硬着头皮上.虽然我这次碰到的是Oracle ...

  10. 【Ural】【1519】Formula 1

    插头DP 本题为CDQ<基于连通性状态压缩的动态规划的……(我忘了)>里的例题!(嗯就是这样……) 先膜拜一下ccy大神……http://blog.sina.com.cn/s/blog_5 ...