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, ...
随机推荐
- iOS 各种编译错误汇总
1.error: macro names must be identifiers YourProject_prefix.pch 原因: 因为你弄脏了预处理器宏,在它处于<Multiple Val ...
- Hive中的一些点
hive严格模式 Hive中Order by和Sort by的区别是什么? hive中order by,sort by, distribute by, cluster by作用以及用法 Hadoop ...
- RK3288 GPIO 输出问题【转】
本文转载自:http://m.blog.csdn.net/jiangdou88/article/details/50158673 #define GPIO_BANK0 (0 ...
- 启动tomcat时,经常遇到的问题 8080 端口被占用
启动tomcat失败时,弹出的窗口如上,说明8080被某个进程占用了 需要把占用8080端口的进程给kill掉 Win+R 输入运行cmd 打开命令提示符cmd.exe netstat -ano|fi ...
- poj 2406 Power Strings(kmp求一个串的重复子串)
题意:重复子串次数 思路:kmp #include<iostream> #include<stdio.h> #include<string.h> using nam ...
- receive和process的过程
(一) receive最终在fuse_kern_chan.c中的fuse_kern_chan_receive函数实现,使用系统调用读取 res = read(fuse_chan_fd(ch), buf ...
- Android font
╔════╦════════════════════════════╦═════════════════════════════╗ ║ ║ FONT FAMILY ║ TTF FILE ║ ╠════ ...
- Watir: 如果安装sougou浏览器,有可能导致Watir不能工作
如果安装了搜狗,Watir::Browser.new并不一定能打开新的IE浏览器.这种情况下,必须卸载搜狗浏览器,当然,attach,find方法还是可以用的
- MSG结构体
typedef struct tagMSG { // msg HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; PO ...
- python学习笔记2-条件语句
#条件语句 ''' if 判断条件: 执行语句…… else: 执行语句…… ''' flag = False name = 'python' if name == 'python': # 判断变量否 ...