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, ...
随机推荐
- 【网络协议】IP协议、ARP协议、RARP协议
IP数据报 IP是TCP/IP协议族中最核心的协议,全部的TCP.UDP.ICMP.IGMP数据都以IP数据报的格式传输.IP仅提供尽力而为的传输服务.假设发生某种错误.IP会丢失该数据.然后发送IC ...
- H5新增表单属性
一.form属性 <form id="test"> <input type="text" placeholder="请输入合适的信息 ...
- 解决移动端页面滚动后不触发touchend事件
解决移动端页面滚动后不触发touchend事件 问题 在移动端页面进行优化时,一般使用touch事件替代鼠标相关事件.用的较多的是使用touchend事件替代PC端的click和mouseup事件. ...
- STM32 DMA中断只进入一次的解决办法
问题解决参见:http://bbs.ednchina.com/BLOG_ARTICLE_3014819.HTM 经过我验证,这个说的是对的.
- JavaScript正则表达式API
1. [代码][JavaScript]代码 参考自<Core JavaScript Reference 1.5> JavaScript正则表达式有两种写法(随便哪种,看个人习惯): ...
- jetty源码剖析
最近使用jetty自己写了一个web server,现在闲了花了一天的时间看了一jetty的源代码,主要以server的启动为主线,进行了剖析,经过阅读对jetty的源码大赞,写的简洁.清晰,架构也不 ...
- [Selenium] IOS 之 ios-driver
从 Selenium 的官方文档来看,推荐用户使用 ios-driver 或 appium 而不是官方发布的 iPone Driver. 他们的地址分别是: http://ios-driver.git ...
- [Selenium] 操作页面元素等待时间
WebDriver 在操作页面元素等待时间时,提供2种等待方式:一个为显式等待,一个为隐式等待,其区别在于: 1)显式等待:明确地告诉 WebDriver 按照特定的条件进行等待,条件未达到就一直等待 ...
- Elasticsearch 安装配置 外网访问 及 后台启动
本文转自http://www.jianshu.com/p/658961f707d8 作者:咪博士 感谢咪博士分享 Elasticsearch的安装总体来说还是相当简单的,当然中间也会有些小坑.不过大家 ...
- 使用webpack报错
意思是: 意思是CLI被移动到了一个专门的包 webpack-cli里了.请安装webpack-cli 的除了webpack本身使用cli当用npm时,使用npm install webpack-cl ...