Palindromic Numbers LightOJ - 1205
题目大意:
求区间内的回文数个数
题目思路:
数位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的更多相关文章
- LightOJ 1205 Palindromic Numbers
数位DP.... Palindromic Numbers Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %l ...
- LightOJ - 1205:Palindromic Numbers (数位DP&回文串)
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- 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 ...
- lightoj 1205 数位dp
1205 - Palindromic Numbers PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- Lightoj1205——Palindromic Numbers(数位dp+回文数)
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- xtu summer individual 1 E - Palindromic Numbers
E - Palindromic Numbers Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %l ...
- 【LightOJ - 1205】Palindromic Numbers
[链接]https://cn.vjudge.net/problem/LightOJ-1205 [题意] 求出L..R范围内的回文个数 [题解] 数位DP; 先求出1..x里面的回文串个数.则做一下前缀 ...
- light 1205 - Palindromic Numbers(数位dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1205 题解:这题作为一个数位dp,是需要咚咚脑子想想的.这个数位dp方程可能不 ...
随机推荐
- springmvc 学习笔记
@Autowired,@RequestMapping,@RequestParam 使用该注解,引入对象时, 可以省略setter getter.减少代码显示. @AutowiredSimService ...
- tar压缩解压文件
查看visualization1.5.tar.gz 压缩包里面的内容: $ tar -tf visualization1.5.tar.gz 解压指定文件JavascriptVisualRelease/ ...
- 关于串session
关于session: 最近在用IE浏览器调试不同用户所拥有的权限功能,出现了串session.串session,主要的流程结构如下: 解决方法: 在IE快捷方式上点击鼠标右键>属性>快捷方 ...
- as依赖解决报错
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.suppor ...
- python3 rrdtool 使用
源自 python自动化运维:技术与最佳实践 并做略微修改 安装 yum install python-rrdtoolyum install rrdtool-devel #因为采集用了psutil模块 ...
- Elastic Stack之搜索引擎基础
Elastic Stack之搜索引擎基础 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.搜索引擎概述 1>.什么是搜索引擎 搜索引擎(Search Engine)是指根 ...
- Spring Boot笔记七:扩展Spring MVC
新建一个类,继承WebMvcConfigurerAdapter package com.vae.springboot.config; import org.springframework.contex ...
- MVC 5 Scaffolder + EntityFramework+UnitOfWork Pattern 代码生成工具
MVC 5 Scaffolder + EntityFramework+UnitOfWork Pattern 代码生成工具集成Visual Studio 2013 MVC 5 Scaffolder + ...
- <HTML深入浅出> 读书笔记
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- 09、 在QQ音乐中查找七里香这首歌的精彩评论
找到七里香这首歌的精彩评论 URL https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg?g_tk=5381&l ...