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 ...
随机推荐
- 利用 C++ 单向链表实现队列
利用C++ 单向链表实现数据结构队列,其实和上一篇基本内容相同,仅仅是插入的时候在链表的尾部插入,取元素都是一样的,都从头部取. #pragma once #include "stdio.h ...
- java正則表達式的坑
java中正則表達式比較有意思,这里列举几个常见的坑 1.[]符号,中括号表示当中的数据都是或的关系 假设[\\w+]是匹配条件 abc能否够匹配的到呢? 首先\\w(注意这里没有中括号)表示a-z ...
- Thinkpad X200 屏幕备案
妈妈蛋,屏幕废物前几天(闪屏->暗->变暗),因此,它只能监视房外 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjk2NTg5MA= ...
- Automatically generate serial number in abap
流水号的产生: 在ABAP开发中,很多地方都需要按照自己的规则生成流水号,把这些流水号保存进透明表,作为唯一标示. 一. 系统中设定流水号 使用T-Code SNRO来创建一个流水号标识对象. 输 ...
- Mac maven环境变量配置
近期一直在学习使用Macbook,在这里记录一下全部遇到的问题 问题起源: 1.Macbook 安装了Eclipse,Eclipse装入插件maven & git , 可是在git中clone ...
- 解决.net的堆碎片化带来的内存占用过大的问题
场景 使用WCF开发的服务端在多个客户端登录后,其服务器的内存占用不断增加. 分析 使用Windbg分析得到内存碎片化严重,其中包含了非常大的空闲空间,最大的一块竟然有150M,真正使用的空间其实很小 ...
- Windows Phone开发(11):常用控件(下)
原文:Windows Phone开发(11):常用控件(下) WP控件大部分都可以从Silverlight中继承过来,这里我也只能拿一部分作演示,对于其它控件如何使用,可以参考SDK相关说明以及Sil ...
- android EditText的美化
今天要做一个页面,有EditText,于是就搞起了它的美化. EditText的美化,我的第一反应是,在EditText的左边设置显示一张图片,这样会比較好看. 设置左边显示图片的属性为:androi ...
- Leetcode 3Sum Closet
二手和3Sum像几乎相同的想法.二进制搜索.关键修剪.但是,在修剪做出很多错误. 然后还有一个更加速了原来的想法O(n^2). #include<iostream> #include &l ...
- Spring常见问题解决办法汇总
解决The prefix 'context' for element 'context:component-scan' is not bound<beans xmlns="http:/ ...
