Mirror Number SPOJ - MYQ10
题意:http://blog.csdn.net/hcbbt/article/details/38349367
稍微改一下http://www.cnblogs.com/hehe54321/p/loj-1205.html就行
#include<cstdio>
#include<cstring>
typedef long long LL;
LL ans[][][];
LL w[];
LL T;
char l[],r[];
LL temp[];
LL dp(LL tot,LL pos,bool pre0,bool limit)
{
if(pos<) return ;
if(!limit&&ans[tot][pos][pre0]!=-)
return ans[tot][pos][pre0];
LL i,res=,end=limit?w[pos]:;
for(i=;i<=end;i++)
{
if(i!=&&i!=&&i!=) continue;
temp[pos]=i;
if(i==&&pre0)
res+=dp(tot-,pos-,,);
//res+=dp(tot,pos-1,1,0);这样会错
else if(pos>tot/)//5-->5,4,3 6-->6,5,4 如果在前一半则可以随便填
res+=dp(tot,pos-,,limit&&i==w[pos]);
else if(temp[pos]==temp[tot-pos+])//如果在后一半就必须和前一半一样
res+=dp(tot,pos-,,limit&&i==w[pos]);
}
if(!limit) ans[tot][pos][pre0]=res;
return res;
}
LL get(char x[])
{
LL len=strlen(x);
for(LL i=;i<len;i++) w[len-i]=x[i]-'';
return dp(len,len,,);
}
bool ok(char x[])
{
LL len=strlen(x);
for(LL i=;i<len;i++)
if(x[i]!=x[len-i-]||(x[i]!=''&&x[i]!=''&&x[i]!=''))
return false;
return true;
}
int main()
{
LL iii;
memset(ans,-,sizeof(ans));
scanf("%lld",&T);
for(iii=;iii<=T;iii++)
{
scanf("%s%s",l,r);
printf("%lld\n",get(r)-get(l)+ok(l));
}
return ;
}
错误点:
错误的ok函数
bool ok(char x[])
{
LL len=strlen(x);
for(LL i=;i<len/;i++)
if(x[i]!=x[len-i-]||(x[i]!=''&&x[i]!=''&&x[i]!=''))
return false;
return true;
}
错在:如果是奇数位,且最中间一位不是0,1,8,其他位满足镜像回文,那么会误判为true(实际为false)。
Mirror Number SPOJ - MYQ10的更多相关文章
- SPOJ MYQ10 (数位DP)
题意 询问区间[a,b]中的Mirror Number的个数,其中Mirror Number是指把它横着翻转后还能表示同样的数字. 思路 注意这个可不是回文数..除了0,1,8,别的数字翻转过后就不是 ...
- 数位DP专题
这周开始刷数位DP,在网上找到一份神级数位DP模板,做起题目来爽歪歪. http://www.cnblogs.com/jffifa/archive/2012/08/17/2644847.html in ...
- 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...
- SPOJ MKTHNUM & POJ 2104 - K-th Number - [主席树模板题]
题目链接:http://poj.org/problem?id=2104 Description You are working for Macrohard company in data struct ...
- SPOJ Number of Palindromes(回文树)
Number of Palindromes Time Limit: 100MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu ...
- Spoj MKTHNUM - K-th Number
题目描述 English Vietnamese You are working for Macrohard company in data structures department. After f ...
- SPOJ:Decreasing Number of Visible Box(不错的,背包?贪心?)
Shadowman loves to collect box but his roommates woogieman and itman don't like box and so shadowman ...
- The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror) B"Even Number Theory"(找规律???)
传送门 题意: 给出了三个新定义: E-prime : ∀ num ∈ E,不存在两个偶数a,b,使得 num=a*b;(简言之,num的一对因子不能全为偶数) E-prime factorizati ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
随机推荐
- SDOI2016R1(不是解题报告)
话说洗澡的时候想了一堆要说的,坐到电脑前反而不知所措了-- 序章 听学长说他们都是省选一周前才停的课.然而我们这届--自聪哥韩大他们在省选两周前悄悄跑路后(据说班主任非常支持),信息小组内部一呼百应, ...
- atitit.eclipse有多少api  扩展点,以及扩展点的设计
atitit.eclipse有多少api 扩展点,以及扩展点的设计 不赞成使用的.作废的以及内部的扩展点 [扩展]页显示了几个你不应该在你的插件中使用的扩展点.在附表C.1的[描写叙述]栏中.我们使 ...
- Leetcode(58)题解:Length of Last Word
https://leetcode.com/problems/length-of-last-word/ 题目: Given a string s consists of upper/lower-case ...
- 1507: [NOI2003]Editor
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MB Submit: 3535 Solved: 1435 [Submit][St ...
- String,StringBuilder与StringBuffer的区别
相信大家看到过很多比较String和StringBuffer区别的文章,也明白这两者的区别,然而自从Java 5.0发布以后,我们的比较列表上将多出一个对象了,这就是StringBuilder类.St ...
- JS中prototype,js原型扩展
作者:轩脉刃(yjf512)出处:(http://www.cnblogs.com/yjf512/)版权声明:本文的版权归作者与博客园共有.欢迎转载阅读,转载时须注明本文的详细链接. 原文 http:/ ...
- jdbc navcat for mysql 连不上远程服务器的原因(安全组设置)
如果你权限,防火墙什么都设置好了,但是还是连不上远程数据库, 那么你就必须要看看你的服务器上安全组的设置(很重要) 这里以阿里云为例子(之前用阿里云服务都没设置),现在阿里云的服务器租的时候就要求配置 ...
- JavaScript正则表达式API
1. [代码][JavaScript]代码 参考自<Core JavaScript Reference 1.5> JavaScript正则表达式有两种写法(随便哪种,看个人习惯): ...
- [Java]手动编译Java
1.安装JDK 2.编写 Example.java 程序放到C 盘 public class Example { public static void main(string[] args) { sy ...
- 使用pngcrush压缩png图片
写在前面: Pngcrush是一个优化的PNG(便携式网络图形)文件.它可以运行在MSDOS窗口中一个命令行,或从UNIX或LINUX命令行.其主要目的是为了 减少PNG IDAT数据 ...