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

代码如下:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#define ll long long
using namespace std;
ll dp[][][];
int bit[],num[];
ll dfs(int pos,int m,int s,bool f)
{
if(!pos) return ;
if(!f&&dp[pos][m][s]!=-) return dp[pos][m][s];
ll ans=;
int e=f?bit[pos]:;
for(int i=;i<=e;i++){
if(!s){
num[pos]=i;
ans+=dfs(pos-,m-!i,s||i,f&&i==e);
}
else{
int t=(m+)>>;
bool flag=m&?pos<t:pos<=t;
if(flag){
if(num[m+-pos]==i)
ans+=dfs(pos-,m,s,f&&i==e);
}
else{
num[pos]=i;
ans+=dfs(pos-,m,s,f&&i==e);
}
}
}
if(!f) dp[pos][m][s]=ans;
return ans;
}
ll cal(ll n)
{
int m=;
while(n){
bit[++m]=n%;
n/=;
}
return dfs(m,m,,);
}
int main()
{
int t,ca=;
ll a,b;
memset(dp,-,sizeof(dp));
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&a,&b);
if(a>b) swap(a,b);
printf("Case %d: %lld\n",++ca,cal(b)-cal(a-));
}
return ;
}

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. squid基础配置

    1 2 3 4 5 6 7 8 9 10 vim /etc/squid/squid.conf    http_port 192.168.1.12:3128 (可写多个) cache_mem 64MB  ...

  2. libevent简介 构成

    libevent简介 libevent是一个事件驱动的网络库,支持跨平台,如Linux, *BSD, MacOS X, Solaris, Windows.支持I/O多路复用,epoll.poll./d ...

  3. iOS学习之UITableView

    一.UITableView的概念 UITabelView继承于UIScrollView,可以滚动. @interface UITableView : UIScrollView <NSCoding ...

  4. iOS学习之UINavigationController

    一.UINavigationController      1.UINavigationController:导航控制器,是iOS中最常用的多视图控制器之一,用它来管理多个视图控制器.可以称为是管理控 ...

  5. OC中NSDictionary(字典)、NSMutableDictionary(可变字典)、NSSet(集合)、NSMutableSet(可变集合)得常用方法

    字典用于保存具有映射关系数据的集合 一个key—value对认为是一个条目(entry),字典是存储key—value对的容器 与数组不同,字典靠key存取元素 key不能重复,value必须是对象 ...

  6. Linux rsync 同步

    rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用.本文主要讲述的是如何自架rsync服务器,以实现文件传输.备份和镜像.相对tar ...

  7. [转]gdb结合coredump定位崩溃进程

    [转]gdb结合coredump定位崩溃进程 http://blog.sina.com.cn/s/blog_54f82cc201013tk4.html Linux环境下经常遇到某个进程挂掉而找不到原因 ...

  8. Entity Framework学习笔记(三)----CRUD(2)

    请注明转载地址:http://www.cnblogs.com/arhat 昨天晚上老魏配的机器终于到了,可是拿回来之后什么都组装好了,唯独差一个非常重要的组件"电源线",老魏那个汗 ...

  9. 启动级别:init 0,1,2,3,4,5,6

    这是个很久的知识点了,只是自己一直都迷迷糊糊的,今天在翻出来好好理解下.. 0:停机 1:单用户形式,只root进行维护 2:多用户,不能使用net file system 3:完全多用户 5:图形化 ...

  10. 闹钟类app构想

    NABC--闹钟app N:我们打算针对那些易健忘的人来制作一款闹钟功能的记事本,具来说服务的对象有很多:有健忘的人,还有情侣,北漂的人及其父母(...),常年见不到亲人(双方),后期我们若提前完成基 ...