思路:搜索的时候是从高位到低位,所以一旦遇到非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. Hadoop之Hive自定义函数的陷阱

    A left join B, 这个B会连到A. 如<A1,B>, <A2,B>,在处理第一条记录的时候将B.clear(),则第二条记录的B是[]空的这是自定义UDF函数必须注 ...

  2. Nginx Gzip 压缩配置

    Nginx Gzip 压缩配置 随着nginx的发展,越来越多的网站使用nginx,因此nginx的优化变得越来越重要,今天我们来看看nginx的gzip压缩到底是怎么压缩的呢? gzip(GNU-Z ...

  3. C语言中函数有输出参数

    #include "stdio.h"void set(int *ch,int a,int *c,int *d){ c[0]=12; c[1]=133; c[2]=14; ch[0] ...

  4. UISegmentedControl swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...

  5. 快速排序QuickSort

    前几天实现了直接插入排序.冒泡排序和直接选择排序这三个基础排序.今天看了一下冒泡排序的改进算法,快速排序.单独记录一下,后面还有归并和基数排序等 快速排序 1.选择一个支点默认为数组第一个元素及arr ...

  6. 程序调试手段之gdb, vxworks shell

    调试一个程序主要用到的功能: 启动程序 设置函数断点 设置数据断点 单步执行 查看内存值 修改内存值 linux下的gdb,和vxworks下的shell 虽然使用方式和调试命令略有不同,但是都能满足 ...

  7. GCC笔记

    The History of GCC 1984年,Richard Stallman发起了自由软件运动,GNU (Gnu's Not Unix)项目应运而生,3年后,最初版的GCC横空出世,成为第一款可 ...

  8. EF:Invalid column name 'Discriminator'.

    错误信息: InnerException: System.Data.SqlClient.SqlExceptionHResult=-2146232060Message=Invalid column na ...

  9. 【BZOJ】【3530】【SDOI2014】数数

    AC自动机/数位DP orz zyf 好题啊= =同时加深了我对AC自动机(这个应该可以叫Trie图了吧……出边补全!)和数位DP的理解……不过不能自己写出来还真是弱…… /************* ...

  10. sublime text3 插件安装

    安装Package control 先打开安装代码的命令行 按 ctrl+~或者 view  -> show console 将下面的代码粘贴到输入框里 按回车 import urllib.re ...