题目大意:

求区间内的回文数个数

题目思路:

  数位dp,先枚举前一半数字,然后填上相应的后一半数字。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#define MAXSIZE 1000005
#define LL long long using namespace std; LL dp[][][];
int temp[MAXSIZE],bit[MAXSIZE]; LL dfs(int pos,int st,int pre,int limit)
{
if(pos < )
return ;
if(!limit && dp[pos][st][pre]!=-)
return dp[pos][st][pre];
int len = limit?bit[pos]:;
LL ans = ;
for(int i=;i<=len;i++)
{
temp[pos] = i;
if(pre== && i==)
{
ans += dfs(pos-,st-,,i==len&&limit);
} else if(pos > st/) //枚举前一半
{
ans += dfs(pos-,st,,i==len&&limit);
} else if(temp[pos] == temp[st-pos+]) //填上后一半
{
ans += dfs(pos-,st,,i==len&&limit);
}
} if(!limit)
dp[pos][st][pre] = ans;
return ans;
} LL Solve(LL n)
{
int pos = ;
memset(dp,-,sizeof(dp));
while(n)
{
bit[++pos] = n%;
n /= ;
}
LL ans = dfs(pos,pos,,);
return ans;
} int main()
{
int T,cns=;
LL n,m;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&n,&m);
if(n > m)
swap(n,m);
LL ans = Solve(m) - Solve(n-);
printf("Case %d: %lld\n",cns++,ans);
}
return ;
}

Palindromic Numbers LightOJ - 1205的更多相关文章

  1. LightOJ 1205 Palindromic Numbers

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

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

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

  3. 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 ...

  4. lightoj 1205 数位dp

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

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

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

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

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

  7. xtu summer individual 1 E - Palindromic Numbers

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

  8. 【LightOJ - 1205】Palindromic Numbers

    [链接]https://cn.vjudge.net/problem/LightOJ-1205 [题意] 求出L..R范围内的回文个数 [题解] 数位DP; 先求出1..x里面的回文串个数.则做一下前缀 ...

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

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

随机推荐

  1. Mac上在终端上解压与压缩

    1.安装rar 1.brew install unrar 2.unrar -version 3.进入需要解压的文件目录下,unrar x 文件夹名.rar 1.tar -xvf [file.tar.g ...

  2. C# string.format用法详解

    String.Format 方法的几种定义: String.Format (String, Object) 将指定的 String 中的格式项替换为指定的 Object 实例的值的文本等效项. Str ...

  3. day14-jdbc案例(简单的curd&分页)

    回顾: mvc jsp的设计模式1: jsp+javabean jsp的设计模式2: jsp+javabean+servlet jsp:展示数据 javabean:封装数据 封装对数据的访问 serv ...

  4. python自动化开发-[第一天]-练习题

    1.使用while循环输入 1 2 3 4 5 6 8 9 10 i = 1 while i < 11: if i == 7: i += 1 continue print (i) i += 1 ...

  5. db mysql / mysql cluster 5.7.19 / my.cnf / max_binlog_cache_size / binlog

    s mysql修改binlog保存的天数 https://blog.csdn.net/Hu_wen/article/details/80582013 查看binlog过期时间,设置的时间为90天,这个 ...

  6. SVN简单的使用

    一.什么是SVN有什么用? SVN是Subversion的简称,是一个开放源代码的版本控制系统.主要是用于团队开发中的资源共享和团队协作. 二.SVN服务器的安装 1.下载安装文件 在下面地址下载Vi ...

  7. java io系列08之 File总结

    本文对File的API和常用方法进行介绍. 转载请注明出处:http://www.cnblogs.com/skywang12345/p/io_08.html File 介绍 File 是“文件”和“目 ...

  8. VS下个人认为比较实用的插件

    懒得打字了,直接贴图

  9. Android弹出窗口

    protected void PopUp() { final PopupWindow popup = new PopupWindow(TestActivity.this); View popView ...

  10. 关于HTTP的笔记

    网上看了一篇关于HTTP的博客,觉得还不错,这里就记下来了. 参考:https://www.cnblogs.com/guguli/p/4758937.html 一.主要特点 1.支持客户/服务器模式2 ...