题目大意:

求区间内的回文数个数

题目思路:

  数位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. MooFest POJ - 1990 (树状数组)

    Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gather ...

  2. please select android sdk

  3. Luogu P2148 [SDOI2009]E&D

    题目链接 \(Click\) \(Here\) 蒟蒻的人生第一道博弈论.真吉尔难啊.... 通常的博弈论写法似乎都是\(SG\)函数打表猜规律.本蒻其实本来想学一下博弈论的证明的,但后来发现果然还是打 ...

  4. php处理文件上传

    注意点: 1.<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" ...

  5. nginx安装配置: configure命令

    configure命令用来配置nginx编译环境. 该命令定义了系统各方面功能,包括允许nginx使用的连接处理方式. 其执行结果是生成一个Makefile文件. configure命令支持如下参数: ...

  6. python机器学习-sklearn挖掘乳腺癌细胞(五)

    python机器学习-sklearn挖掘乳腺癌细胞( 博主亲自录制) 网易云观看地址 https://study.163.com/course/introduction.htm?courseId=10 ...

  7. 信用评分卡 (part 1 of 7)

    python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...

  8. JAVA核心技术I---JAVA基础知识(单例模式和final关键字)

    一:单例模式 C++设计模式中提及,不再赘述设计模式---对象性能模式之单例模式(Singleton) public class single{ static single Instance=new ...

  9. netty的HelloWorld演示

    pom <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artif ...

  10. [leetcode-120] 三角形最小路径和

    三角形最小路径和 (1过) 给定一个三角形,找出自顶向下的最小路径和.每一步只能移动到下一行中相邻的结点上. 例如,给定三角形: [ [2], [3,4], [6,5,7], [4,1,8,3] ] ...