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

    一篇Sun官方网站上介绍JConsole使用的文章,前段时间性能测试的时候大概翻译了一下以便学习,今天整理一下发上来,有些地方也不知道怎么翻,就保留了原文,可能还好理解点,呵呵,水平有限,翻的不好,大 ...

  2. Andrew Stankevich's Contest (21) J dp+组合数

    坑爹的,,组合数模板,,, 6132 njczy2010 1412 Accepted 5572 MS 50620 KB C++ 1844 B 2014-10-02 21:41:15 J - 2-3 T ...

  3. App后台运行通知函数

    
[[UIApplicationsharedApplication] beginBackgroundTaskWithExpirationHandler: ^() { //程序在10分钟内未被系统关闭或 ...

  4. java基础 6 基本类型与运算

    1 包装类型 Integer的缓存池为   -128 - 127: 八个基本类型   占bit  与字节  8 bit = 1 字节 boolean  1     byte  8    char   ...

  5. jquery 获取浏览器窗口的可视区域高度 宽度 滚动条高

    原文:http://www.open-open.com/code/view/1421827925437 alert($(window).height()); //可视区域高度 alert($(docu ...

  6. Word2vector原理

    词向量: 用一个向量的形式表示一个词 词向量的一种表示方式是one-hot的表示形式:首先,统计出语料中的所有词汇,然后对每个词汇编号,针对每个词建立V维的向量,向量的每个维度表示一个词,所以,对应编 ...

  7. es删除文档或者删除索引

    es删除文档或者删除索引 学习了:https://www.imooc.com/video/15771 删除文档: DELETE http://127.0.0.1:9200/people/man/1 删 ...

  8. 三联动 支持ie6,ie7 省,市,区

    三联动 支持ie6,ie7 省,市,区 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <tit ...

  9. app具体介绍界面-01

    在我们的上一篇博客中,我们介绍了首页中的app列表界面怎样完毕.这个ListView以及其Adapter会在我们后面的界面中重用,所以这个是比較重要的,在这一篇博客中,我们先完毕app具体介绍界面的一 ...

  10. java 短信猫发送短信的方法

    用java实现短信收发的功能,目前一般项目中短信群发功能的实现方法大致有下面三种: ·                 1. 向运行商申请短信网关,不需要额外的设备,利用运行商提供的API调用程序发送 ...