稍微用脑子想一想,要是一个回文数,要么s[i]==s[i+1]要么s[i]==s[i+2]就可以实锤了

所以多开两维表示最近两位选的是什么数就完了

注意前导0

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int mbit=; LL f[mbit][mbit][mbit];//第i位,第i位和第i-1位放的是啥 -----> 非回文数个数 (有前导零)
LL g[mbit];//枚举到第i位 -----> 非回文数个数 (无前导零)
void init()
{
g[]=,g[]=;
for(int i=;i<=;i++)
for(int j=;j<=;j++)
if(i!=j)f[][i][j]=;
for(int i=;i<=;i++)
{
for(int u=;u<=;u++)
for(int v=;v<=;v++) if(u!=v)
for(int w=;w<=;w++) if(u!=w&&v!=w)
f[i][u][v]+=f[i-][v][w];
g[i]=g[i-];
for(int u=;u<=;u++)
for(int v=;v<=;v++)
g[i]+=f[i][u][v];
}
} int clen,c[mbit];
LL getnum(LL k)
{
if(k<)return ;
LL t=k;clen=;
while(t>){c[++clen]=t%;t/=;}
if(clen==)clen++;
c[clen+]=-;c[clen+]=-; LL ret=;
for(int i=clen;i>=;i--)
{
int li=c[i]-;if(i==)li++;
for(int j=;j<=li;j++)
{
if(j==c[i+]||j==c[i+])continue;
if(i==)ret++;
else if(i==)
{
for(int k=;k<=;k++)
if(k!=c[i+]&&(k!=j||(i==clen&&j==)))ret++;
}
else
{
if(i==clen&&j==)
{
ret+=g[i-];
continue;
} for(int u=;u<=;u++)
for(int v=;v<=;v++)
if(u!=v&& u!=c[i+]&&u!=j&&v!=j )
ret+=f[i-][u][v];
}
}
if(c[i]==c[i+]||c[i]==c[i+])break;
}
return ret;
} int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
init();
LL L,R;
scanf("%lld%lld",&L,&R);
printf("%lld\n",getnum(R)-getnum(L-)); return ;
}

bzoj3134: [Baltic2013]numbers的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  3. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  4. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  5. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  6. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  7. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  8. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  9. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

随机推荐

  1. C#.net磁盘管理以及文件操作

    原文发布时间为:2008-08-08 -- 来源于本人的百度文章 [由搬家工具导入]    需要引入的命名空间: using System.IO;using System.Text; private ...

  2. [转] Python 常用第三方模块 及PIL介绍

    原文地址 除了内建的模块外,Python还有大量的第三方模块. 基本上,所有的第三方模块都会在PyPI - the Python Package Index上注册,只要找到对应的模块名字,即可用pip ...

  3. java验证身份证号码是否有效源代码 wn25的头像 wn25 23 2015-01-04 20:09 6 基本信息 Java × 1 浏览

    原文:http://www.open-open.com/code/view/1420373343171 1.描述 用java语言判断身份证号码是否有效,地区码.出身年月.校验码等验证算法 2.源代码 ...

  4. 修复OS X的Finder中文档 打开方式中重复程序的问题

    如上图,OS X在使用一段时间后,有些软件就会重复注册打开方式,对于有洁癖的人,这是难以接受的事. 不过有个命令可以很简单的把重复项给去掉. /System/Library/Frameworks/Co ...

  5. PHP网站渗透中的奇技淫巧:检查相等时的漏洞

    PHP是现在网站中最为常用的后端语言之一,是一种类型系统 动态.弱类型的面向对象式编程语言.可以嵌入HTML文本中,是目前最流行的web后端语言之一,并且可以和Web Server 如apache和n ...

  6. 使用FMDB多线程訪问数据库,及database is locked的问题

    今天最终攻克了多线程同一时候訪问数据库时,报数据库锁定的问题.错误信息是: Unknown error finalizing or resetting statement (5: database i ...

  7. 机房收费系统(VB.NET)个人版总结

    重构版个人机房收费系统大概从暑假开学開始进行.花了不到一个半月的时间才完毕.以下对我在重构过程中的一写理解. 1.系统设计一个非常重要的目的就是重用.而要做到重用,低耦合是最有效的手段回想一下我们C/ ...

  8. Intel的东进与ARM的西征(4)--理想的星空,苹果处理器之野望

    http://www.36kr.com/p/200031.html “人生五十年,如梦亦如幻.有生斯有死,壮士何所憾?”之所以没有遗憾,是因为有了理想. 公元 1582 年,日本战国时期最著名的霸主, ...

  9. SVN——库合并

    从下午開始做库的合并.刚開始一直将路径弄错.后来纠结至死的时候,finally  and finally,succeed~ 库合并是这样子的: 如今,我要把项目1这个库合并到部门1的项目1目录中,为了 ...

  10. IPv4与IPv6数据报格式

    IPv4: IPv4数据报中的字段: 版本号:规定了数据报的IP协议版本,通过查看版本号,路由器能够确定如何解释IP数据报的剩余部分,因为不同IP版本使用不同的数据报格式. 首部长度:IPv4数据报可 ...