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的更多相关文章

  1. SPOJ MYQ10 (数位DP)

    题意 询问区间[a,b]中的Mirror Number的个数,其中Mirror Number是指把它横着翻转后还能表示同样的数字. 思路 注意这个可不是回文数..除了0,1,8,别的数字翻转过后就不是 ...

  2. 数位DP专题

    这周开始刷数位DP,在网上找到一份神级数位DP模板,做起题目来爽歪歪. http://www.cnblogs.com/jffifa/archive/2012/08/17/2644847.html in ...

  3. 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)

    [SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...

  4. SPOJ MKTHNUM & POJ 2104 - K-th Number - [主席树模板题]

    题目链接:http://poj.org/problem?id=2104 Description You are working for Macrohard company in data struct ...

  5. SPOJ Number of Palindromes(回文树)

    Number of Palindromes Time Limit: 100MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu ...

  6. Spoj MKTHNUM - K-th Number

    题目描述 English Vietnamese You are working for Macrohard company in data structures department. After f ...

  7. SPOJ:Decreasing Number of Visible Box(不错的,背包?贪心?)

    Shadowman loves to collect box but his roommates woogieman and itman don't like box and so shadowman ...

  8. 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 ...

  9. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

随机推荐

  1. mysql的DUPLICATE KEY

    经常遇到这样的情景,向一个表里插入一条数据,如果已经存在就更新一下,用程序实现麻烦而且在并发的时候可能会有问题,这时用mysql的DUPLICATE KEY 很方便 用法如下: INSERT INTO ...

  2. Apache Qpid Broker的安全机制

    一.     Apache Qpid的安全机制简介 Apache Qpid提供多种安全机制,包括用户认证.规则定制的授权.消息加密和数字签名等.Apache Qpid使用SASL框架实现对用户身份的认 ...

  3. LeetCode(26)题解:Remove Duplicates from Sorted Array

    https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Given a sorted array, remove the ...

  4. 前端遇上Go: 静态资源增量更新的新实践

    前端遇上Go: 静态资源增量更新的新实践https://mp.weixin.qq.com/s/hCqQW1F8FngPPGZAisAWUg 前端遇上Go: 静态资源增量更新的新实践 原创: 洋河 美团 ...

  5. django-sso单点登陆的实现

    环境准备 环境规格: python3.5 django2.0 django-simple-sso-0.14 环境安装: pip install django-simple-sso-0.14 环境说明: ...

  6. linux 一个超简单的makefile

    makefile 自动化变量:   $@ : 规则的目标文件名  例如:main:main.o test.o                    g++ -Wall -g  main.o test. ...

  7. bzoj3136: [Baltic2013]brunhilda

    这个题为什么会放在数据结构啊 首先因为有决策包容性,对于一个n每次必然选择一个n%p最大的p,令n减n%p 设fi表示i变成0的步数的话,同样我们可以知道f是有单调性的 假如fd能转移到fk,首先d一 ...

  8. POJ3074 Sudoku —— Dancing Links 精确覆盖

    题目链接:http://poj.org/problem?id=3074 Sudoku Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  9. String bulit-in function

    tip: 和tuple一样,字符串也是不可变的类型,字符串的内建函数有非常多,我们一一举例来看看他们的作用 下面是用dir(str) 输出的内容: ['__add__', '__class__', ' ...

  10. 格式化磁盘,提示 is apparently in use by the system

    一般是被mdadm占用着. 使用  cat /proc/mdstat 查看所有 找到欲格式化盘符号. 使用 mdadm --stop /dev/md0 mdadm --remove /dev/md0 ...