数位DP。。。。

Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

Description

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

4

1 10

100 1

1 1000

1 10000

Sample Output

Case 1: 9

Case 2: 18

Case 3: 108

Case 4: 198

Source

Problem Setter: Jane Alam Jan

[Submit]   [Go Back]   [Status]

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long int LL; int a[70];
LL dp[70][70]; LL dfs(int len,int l,int r,bool limit,bool ok)
{
if(l<r) return !limit||(limit&&ok);
if(!limit&&~dp[len][l])
return dp[len][l];
LL ret=0;
int mx=limit?a[l]:9;
for(int i=0;i<=mx;i++)
{
if(l==len-1&&i==0)
continue;
int g=ok;
if(g) g=a[r]>=i;
else g=a[r]>i;
ret+=dfs(len,l-1,r+1,limit&&i==mx,g);
}
if(!limit)
dp[len][l]=ret;
return ret;
} LL gaoit(LL n)
{
if(n<0) return 0;
if(n==0) return 1;
int len=0;
while(n){a[len++]=n%10;n/=10;}
LL ret=1;
for(int i=len;i>=1;i--)
ret+=dfs(i,i-1,0,i==len,1);
return ret;
} int main()
{
int T_T,cas=1;
cin>>T_T;
memset(dp,-1,sizeof(dp));
while(T_T--)
{
LL x,y;
cin>>x>>y;
if(x>y) swap(x,y);
printf("Case %d: %lld\n",cas++,gaoit(y)-gaoit(x-1));
}
return 0;
}

LightOJ 1205 Palindromic Numbers的更多相关文章

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

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

  2. light oj 1205 - Palindromic Numbers 数位DP

    思路:搜索的时候是从高位到低位,所以一旦遇到非0数字,也就确定了数的长度,这样就知道回文串的中心点. 代码如下: #include<iostream> #include<cstdio ...

  3. lightoj 1205 数位dp

    1205 - Palindromic Numbers    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...

  4. LightOJ - 1205:Palindromic Numbers (数位DP&回文串)

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  5. LightOJ - 1396 :Palindromic Numbers (III)(逐位确定法)

    Vinci is a little boy and is very creative. One day his teacher asked him to write all the Palindrom ...

  6. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  7. Lightoj1205——Palindromic Numbers(数位dp+回文数)

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  8. xtu summer individual 1 E - Palindromic Numbers

    E - Palindromic Numbers Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %l ...

  9. Palindromic Numbers LightOJ - 1205

    题目大意: 求区间内的回文数个数 题目思路: 数位dp,先枚举前一半数字,然后填上相应的后一半数字. #include<cstdio> #include<cstring> #i ...

随机推荐

  1. vb.net版机房收费——助你学会七层架构(一)

    我自己写机房的时候,看非常多高人的博客,各种的借鉴,当初务必的纠结,如今整个机房敲完了,写这篇博客给大家一个总体上的.简单理解的七层,期望大家看完这篇文章之后,不会这个纠结了. 首先大家得看了我的上一 ...

  2. 完美去除WPF按钮的边框

    主页面背影图片, 添加5个功能按钮,并设置按钮的Background和BorderBrush为Transparent,好像没有问题,运行效果 不仅有一个发光的边框,而且当鼠标经过时,按钮就不在透明, ...

  3. dede时间格试,dede时间标签

    dede的日期时间格式[field:pubdate function='strftime("时间",@me'/]这个是固定格式,(利用strftime()函数格式化时间),因些只需 ...

  4. http协议之cookie标准RFC6265介绍

      [Docs] [txt|pdf] [draft-ietf-httpst...] [Diff1] [Diff2] [Errata] PROPOSED STANDARD Errata Exist In ...

  5. 第三章 AOP 基于@AspectJ的AOP

    在前面,我们分别使用Pointcut.Advice.Advisor接口来描述切点.增强.切面.而现在我们使用@AdpectJ注解来描述. 在下面的例子中,我们是使用Spring自动扫描和管理Bean. ...

  6. Oracle SQL Lesson (1) - 使用SQL Select语句获取数据

    第一节课: 启动数据库并且使用特定用户连接:su - oracle; 启动sqlplus并且使用sys连接:conn / as sysdba; 启动数据库:startup; 解锁用户:alter us ...

  7. 新型I/O架构引领存储之变(四)

    新型I/O架构引领存储之变(四) 作者:廖恒 应对挑战--商务及技术考量 本文前面的部分分析了砖块模式与生俱来的总拥有成本(TCO)过高的问题.为了战胜这一挑战,超大规模数据中心的运营者须要从两个不同 ...

  8. FZUOJ Problem 2178 礼品配送

    Problem 2178 礼物分配 题目链接: Click Here~ Problem Description 在双胞胎兄弟Eric与R.W的生日会上,他们共收到了N个礼物,生日过后他们决定分配这N个 ...

  9. BestCoder Round#11div2 1003

    ----- 有时候如果枚举起点超时,那么试试枚举终点. 枚举每一个i为终点(0<= i < n),且维护起点下标startPos 对于终点i,cnt[str[i]] ++,   如果小于等 ...

  10. Linux学习笔记——例说makefile 头文件查找路径

    0.前言     从学习C语言開始就慢慢開始接触makefile,查阅了非常多的makefile的资料但总感觉没有真正掌握makefile,假设自己动手写一个makefile总认为非常吃力.所以特意借 ...