LightOJ 1205 Palindromic Numbers
数位DP。。。。
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 j (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
|
![]() |
#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的更多相关文章
- light 1205 - Palindromic Numbers(数位dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1205 题解:这题作为一个数位dp,是需要咚咚脑子想想的.这个数位dp方程可能不 ...
- light oj 1205 - Palindromic Numbers 数位DP
思路:搜索的时候是从高位到低位,所以一旦遇到非0数字,也就确定了数的长度,这样就知道回文串的中心点. 代码如下: #include<iostream> #include<cstdio ...
- lightoj 1205 数位dp
1205 - Palindromic Numbers PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
- 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 ...
- [暑假集训--数位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 ...
- Palindromic Numbers LightOJ - 1205
题目大意: 求区间内的回文数个数 题目思路: 数位dp,先枚举前一半数字,然后填上相应的后一半数字. #include<cstdio> #include<cstring> #i ...
随机推荐
- MySQL创建用户权限结果Trigger失败
说来惭愧,MySQL我已经在只将用于,非常赞赏阶段. 甚至一些比较深层次的管理,不熟悉如何,我们要加强啊! 最近.系统测试,使用MySQL数据库,你需要在表上创建触发器.该数据库是安装在机.但.在任何 ...
- windows phone 获取手机图片库中图片(4)
原文:windows phone 获取手机图片库中图片(4) 前置条件:手机和电脑未连接或连接电脑Zune软件关闭(与Zune软件连接时不允许访问图片库): 版本7.1 获取手机图片库图片的两种方式: ...
- Android如何获得手机power_profile.xml文件
上的能量消耗进行最近的测试,阅读文章一个月,最后,我们发现了一些新的想法,但产生的问题.那 工作无法再进行下去. 在Android手机中,对于手机中的每一个部件(cpu.led.gps.3g等等)执行 ...
- swift学习笔记(六)析关闭过程和使用分配给属性的默认值
一.通过关闭和功能的默认实现财产值 当存储属性默认值需要定制,能为客户提供通过关闭或全局函数的自定义默认值. 注意:全局函数的结构,和枚举使用keywordstatic大喊 用classkeyw ...
- C++转让Lua
转载请注明出处:http://blog.csdn.net/zhy_cheng/article/details/39756423 我使用的cocos2d-x版本号是2.3.3.先在一个C++projec ...
- BZOJ 3172([Tjoi2013]单词-后缀数组第一题+RMQ)
3172: [Tjoi2013]单词 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 268 Solved: 145 [ Submit][ St ...
- 【原创】leetCodeOj --- Sliding Window Maximum 解题报告
天,这题我已经没有底气高呼“水”了... 题目的地址: https://leetcode.com/problems/sliding-window-maximum/ 题目内容: Given an arr ...
- 移植 libuv 至 Visual C++ 6.0 并支持 Windows XP 编译系统
移植版本 libuv:https://github.com/liigo/libuv-vc6 (支持VC6和XP.作者Liigo). 我从一年前(大概2013年6,7月份)開始在业余时间做这项移植工作, ...
- 【Android开发经验】Android举UI设计经验
转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 1.Android眼下的主流设备分辨率为480×800.720×1280.1080×1920,单位是像素.在 ...
- SpringMVC 上下文webApplicationContext
使用listener听众载入配置,一般Struts+Spring+Hibernate是使用listener监听器的.例如以下 <listener> <listener-class&g ...
