稍微用脑子想一想,要是一个回文数,要么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. cf21D Traveling Graph

    You are given undirected weighted graph. Find the length of the shortest cycle which starts from the ...

  2. linux和windows下分别如何查看电脑是32位的还是64位?

    WINDOWS下查看的方法: 方法一. 在开始→运行中输入“winver”,如果您的系统是64位的,会明确标示出“x64 edition”. 方法二.(推荐) 在cmd窗口中输入systeminfo回 ...

  3. UVa10539

    http://vjudge.net/problem/UVA-10539 先打出来sqrt(n)以内的素数表,然后对于每个素数x,他对答案的贡献就是最大的p使x^p<=n,即log(x,n).注意 ...

  4. 在App_Data中创建数据库获取连接串简便方法!

    原文发布时间为:2008-07-25 -- 来源于本人的百度文章 [由搬家工具导入] 1、在App_Data右击添加一个SQL数据库2、双击该数据库,在左边添加表,并显示表数据进行添加数据3、把刚刚创 ...

  5. MySQL 中 key, primary key ,unique key,index的区别

    一.key与primary key区别 CREATE TABLE wh_logrecord ( logrecord_id int(11) NOT NULL auto_increment, user_n ...

  6. IOS开发之触摸背景关闭键盘的代码实现

    直接上代码: // 触摸背景,关闭键盘 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch ...

  7. Redis命令行之Zset

    一.Redis之Zset简介 1. 有序集合Zset是String类型的有序集合. 2. Zset中每个元素都会关联一个double类型的分数值,redis通过分数值来为集合中所有成员进行从小到大排序 ...

  8. 王垠:完全用Linux工作 (2003)

    完全用Linux工作,抛弃windows 我已经半年没有使用 Windows 的方式工作了.Linux 高效的完成了我所有的工作. GNU/Linux 不是每个人都想用的.如果你只需要处理一般的事务, ...

  9. Easy sssp(spfa)(负环)

    vijos    1053    Easy sssp 方法:用spfa判断是否存在负环 描述 输入数据给出一个有N(2 <= N <= 1,000)个节点,M(M <= 100,00 ...

  10. python decode unicode encode

    字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(en ...