bzoj3134: [Baltic2013]numbers
稍微用脑子想一想,要是一个回文数,要么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的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [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 ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
随机推荐
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- VirtualBox 下主机与虚拟机以及虚拟机之间互通信配置
引用链接:1)http://www.it165.net/os/html/201401/7063.html 2)http://www.cnblogs.com/sineatos/p/4489620.htm ...
- android源码mk文件里的TARGET_OUT指向哪里?
android源码核心变量大都在build/core/envsetup.mk中建立 在该文件中,可以找到 TARGET_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_ ...
- BestCoder Round #25 1002 Harry And Magic Box [dp]
传送门 Harry And Magic Box Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- scanf printf函数返回值
1. scanf 函数是有返回值的,它的返回值可以分成三种情况 1) 正整数,表示正确输入参数的个数.例如执行 scanf("%d %d", &a, &b); ...
- KJ面试
1.css input checkbox和radio样式美化 <span class="pay_list_c1 on"> <input type="ra ...
- Docker-PostgresSQL
Postgresql Docker安装运行 mac环境: 1.拉取官方镜像,并创建容器 zhoumatoMacBook-Pro:~ zhou$ docker search postgresql NA ...
- 2017 ACM/ICPC Asia Regional Xian Online 记录
题目链接 Xian
- go语言学习之路四:字典
关联数组:(哈希或者字典) Map是go内置关联数据类型,字典是通过Key来访问Value的,访问格式如下: Value=mapName[key] 其实数组可以看做是一个键值类型为整型的字典,可以说数 ...
- VS调试时不加载符号
加载符号,能够让调试时进入系统的dll中,甚至能达到汇编语言的深度,让你调试时能够逐行进行.但是加载符号的话,会使得每次调试,增加进入到首个断点的时间. 而且有时候也非必要加载符号,它的取消可以使用下 ...