1205 - Palindromic Numbers
Time Limit: 2 second(s) Memory Limit: 32 MB

A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this problem you will be given two integers i j, you have to find the number of palindromic numbers between i and j (inclusive).

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case starts with a line containing two integers i j (0 ≤ i, j ≤ 1017).

Output

For each case, print the case number and the total number of palindromic numbers between i and (inclusive).

Sample Input

Output for Sample Input

4

1 10

100 1

1 1000

1 10000

Case 1: 9

Case 2: 18

Case 3: 108

Case 4: 198


PROBLEM SETTER: JANE ALAM JAN
题意:
求区间内回文串数的个数
//开个数组存一下回文串,还要处理前导零。sta表示到目前为止是否合法
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int t,bit[],num[];
ll f[][][],P,Q;
ll dfs(int pos,int s,int sta,bool limit)
{
if(pos==) return sta;
if(!limit&&f[pos][s][sta]!=-) return f[pos][s][sta];
int max_b=(limit?bit[pos]:);
ll ans=;
for(int i=;i<=max_b;i++){
num[pos]=i;
if(pos==s&&i==)
ans+=dfs(pos-,s-,sta,limit&&(i==max_b));
else if(sta&&pos<=s/)
ans+=dfs(pos-,s,num[s-pos+]==i,limit&&(i==max_b));
else ans+=dfs(pos-,s,sta,limit&&(i==max_b));
}
if(!limit) f[pos][s][sta]=ans;
return ans;
}
ll solve(ll x)
{
if(x<) return ;
int pos=;
while(x){
bit[++pos]=x%;
x/=;
}
return dfs(pos,pos,,);
}
int main()
{
memset(f,-,sizeof(f));
scanf("%d",&t);
for(int cas=;cas<=t;cas++){
scanf("%lld%lld",&P,&Q);
if(P>Q) swap(P,Q);
printf("Case %d: %lld\n",cas,solve(Q)-solve(P-));
}
return ;
}

lightoj 1205 数位dp的更多相关文章

  1. lightoj 1021 (数位DP)

    题意:给你一个b进制的数,再给你一个十进制数k,你可以重新排列b进制数的每一位得到其他b进制数,问你这些数中有多少可以整除k? 思路:数位dp. #include <cstdio> #in ...

  2. LightOJ - 1032 数位DP

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...

  3. light oj 1205(数位DP)

    题目描述: 求给定区间中的回文数有多少个? 首先明确一点,如果一个数是回文数,那么给这个数两边加上相同的数,那么这个数还是回文数. 根据这点就可以进行递推了,p[start][end]=9*p[sta ...

  4. Lightoj 1068(数位DP)

    求一段区间中被k整除,各个位数相加之和被k整除的数的个数. 这不是重点,重点是k太大了,最大值有10000,所以不能直接开那么大的数组. 仔细分析一下可以发现,由于数最大是2的31次方(2147483 ...

  5. Lightoj 1140(数位DP)

    求一个区间内的数含有多少个0. dp[len][pre]表示长度为len的数,含有pre个0. 需要加一个标记,来表示前缀是否为0(可以是一串连续的0),如果前缀一直为0,就一直搜,如果前缀不为0,就 ...

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

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

  7. LightOJ 1032 - Fast Bit Calculations 数位DP

    http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表 ...

  8. LightOJ 1068 Investigation (数位dp)

    problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数 ...

  9. lightoj 1021 - Painful Bases(数位dp+状压)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1021 题解:简单的数位dp由于总共就只有16个存储一下状态就行了.求各种进制能 ...

随机推荐

  1. Navicat新建查询,系统找不到指定路径 独家解决办法

    Navicat新建查询系统找不到指定路径,很多人用了网上流行的那些解决办法,还是无法解决.比如: https://jingyan.baidu.com/article/86112f1387a713273 ...

  2. 20172325『Java程序设计』课程 结对编程练习_四则运算第二周阶段总结

    20172325『Java程序设计』课程 结对编程练习_四则运算第二周阶段总结 结对伙伴 学号:20172306 姓名:刘辰 结对伙伴博客链接 刘辰同学对编程的积极程度很高,并且在编程能力上很不错,有 ...

  3. An internal error occurred during: "Launching MVC on Tomcat 7.x".

    删除工作空间下的“/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.genuitec.eclipse.ast.deploy.core ...

  4. ubuntu16.04+cuda8.0+caffe

    =========== 如果出现nvidia-smi failed to communicate with nvidia driver,循环登录情况,则: sudo apt-get remove -- ...

  5. 树莓派与Arduino Leonardo使用NRF24L01无线模块通信之基于RF24库 (三) 全双工通信

    设计思路 Arduino Leonardo初始化为发送模式,发送完成后,立即切换为接收模式,不停的监听,收到数据后立即切换为发送模式,若超过一定时间还为接收到数据,则切换为发送模式. 树莓派初始化为接 ...

  6. Alpha冲刺阶段博客汇总

    第一篇(冲刺前安排):http://www.cnblogs.com/Aragaki-Yui/p/8893752.html 第二篇(冲刺第一天):http://www.cnblogs.com/Araga ...

  7. excel文件怎么使用php进行处理

    1.可以通过phpmyadmin导入csv文件 2.也可以直接使用php 处理已经将excel另存为.csv后缀的文件, 通过php专门处理csv文件的函数 如 fgetcsv() <?php ...

  8. [转贴] IPSEC From 知乎

    作者:埃文科技链接:https://zhuanlan.zhihu.com/p/44874772来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 认识IPSec IPSec ...

  9. check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 7

    第一种是:解决MySQL的版本问题(我用的是mysql 5.5版本),mysql 5.0版本以后的数据库方言是:org.hibernate.dialect.MySQ5LInnoDBDialect.第二 ...

  10. 第218天:Angular---模块和控制器

    1.使用NG实现双边数据绑定 所有需要ng管理的代码必须被包裹在一个有ng-app指令的元素中ng-app是ng的入口,表示当前元素的所有指令都会被angular管理(对每一个指令进行分析和操作) & ...