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, ...
随机推荐
- H5新增表单属性
一.form属性 <form id="test"> <input type="text" placeholder="请输入合适的信息 ...
- java中InputStream String
Java 中获取输入流时,有时候须要将输入流转成String,以便获取当中的内容 ,以下总结一下 InputStream 转成String 的方式 方法1: public String conver ...
- 使用jsoncpp解析生成json
在此站点下载jsoncpp(https://sourceforge.net/projects/jsoncpp/这个站点的版本较旧) 在电脑上安装Python,运行amalgamate.py,生成的di ...
- 20170228 METHOD handle_data_changed-
CALL METHOD er_data_changed->add_protocol_entry METHOD handle_data_changed. DATA: ls_modi TYPE ...
- redis10---Setbit 的实际应用
Setbit 的实际应用 场景: 1亿个用户, 每个用户 登陆/做任意操作 ,记为 今天活跃,否则记为不活跃 每周评出: 有奖活跃用户: 连续7天活动,每月评,等等. 思路: Userid dt ac ...
- ES6 一些新特性的总结
一.箭头函数 ES6中新增了一个箭头函数 ()=>,箭头函数通俗点讲就是匿名函数.箭头函数还有不同点在于改变函数中this,和js中的.bind 的方法差不多,继承后指向的不是最新的函数, ...
- HDU4280 Island Transport —— 最大流 ISAP算法
题目链接:https://vjudge.net/problem/HDU-4280 Island Transport Time Limit: 20000/10000 MS (Java/Others) ...
- LoadRunner 技巧之 IP欺骗
IP欺骗也是也loadrunner自带的一个非常有用的功能. 需要使用ip欺骗的原因:1.当某个IP的访问过于频繁,或者访问量过大是,服务器会拒绝访问请求,这时候通过IP欺骗可以增加访问频率和访问量, ...
- SPOJ:K-Query Online(归并树)
Given a sequence of n numbers a1, a2, ..., an and a number of k-queries. A k-query is a triple (i, j ...
- [Selenium] The most commonly used CSSSelector
CSSSelector Example Description element.element div.dropdown Select all <div> elements whose ...