Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation of x is pairwised different.
Given (L,R,K), please count how many K-wolf numbers in range of L,RL,R

.

Input

The input contains multiple test cases. There are about 10 test cases.

Each test case contains three integers L, R and K.

1≤L≤R≤1e18
2≤K≤52≤K≤5

Output

For each test case output a line contains an integer.

Sample Input

1 1 2
20 100 5

Sample Output

1
72

问有多少个数,任意连续k位都不相同

记一下前k-1位,有没有前导零

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,len,l,r,k;
LL f[][][];
int zhan[];
int d[];
inline LL dfs(int now,int stat,int lead,int fp)
{
if (now==)return ;
if (!fp&&f[now][stat][lead]!=-)return f[now][stat][lead];
LL ans=,mx=fp?d[now-]:;
int lst=;
for(int i=now;i<=min(now+k-,len);i++)if (zhan[i]!=-)lst|=<<zhan[i];
for (int i=;i<=mx;i++)
{
if (lst&(<<i))continue;
if (i==&&lead&&now-!=)zhan[now-]=-;else zhan[now-]=i;
if (zhan[now-]!=-)lst|=(<<i);
ans+=dfs(now-,lst,lead&&i==&&now-!=,fp&&(i==d[now-]));
if (zhan[now-]!=-)lst-=(<<i);
}
if (!fp)f[now][stat][lead]=ans;
return ans;
}
inline LL calc(LL x)
{
if (!x)return ;
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
for (int i=;i<=d[len];i++)
{
if (i==&&len!=)zhan[len]=-;else zhan[len]=i;
if (zhan[len]!=-)sum+=dfs(len,<<zhan[len],zhan[len]==-,i==d[len]);
else sum+=dfs(len,,zhan[len]==-,i==d[len]);
zhan[len]=-;
}
return sum;
}
main()
{
while (~scanf("%lld%lld%lld",&l,&r,&k))
{
memset(f,-,sizeof(f));
printf("%lld\n",calc(r)-calc(l-));
}
}

hdu 5787

[暑假集训--数位dp]hdu5787 K-wolf Number的更多相关文章

  1. [暑假集训--数位dp]hdu3709 Balanced Number

    A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...

  2. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  3. [暑假集训--数位dp]hdu3555 Bomb

    The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...

  4. [暑假集训--数位dp]hdu3652 B-number

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...

  5. [暑假集训--数位dp]hdu2089 不要62

    杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...

  6. [暑假集训--数位dp]hdu5898 odd-even number

    For a number,if the length of continuous odd digits is even and the length of continuous even digits ...

  7. [暑假集训--数位dp]LightOJ1140 How Many Zeroes?

    Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...

  8. [暑假集训--数位dp]LightOj1032 Fast Bit Calculations

    A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...

  9. [暑假集训--数位dp]cf55D Beautiful numbers

    Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer numb ...

随机推荐

  1. linux程序安装及包管理

    程序包的封装类型: RPM软件包:扩展名为“.rpm”,使用rpm命令安装. DEB软件包:扩展名为“.deb”,使用DPKG包管理器. 源代码软件安装:程序员开发完成的原始代码,一般制作成“.tar ...

  2. $|^|\z|\Z|/a|/l

    #!/usr/bin/perl use strict; use warnings; foreach(<>) { if (/(\w*)/a){print "$1\n";} ...

  3. python报错UnicodeDecodeError:

    Python 里面的编码和解码也就是 unicode 和 str 这两种形式的相互转化.编码是 unicode -> str,相反的,解码就 是 str -> unicode.剩下的问题就 ...

  4. 消息队列之 Kafka

    转 https://www.jianshu.com/p/2c4caed49343 消息队列之 Kafka 预流 2018.01.15 16:27* 字数 3533 阅读 1114评论 0喜欢 12 K ...

  5. mysql EOF

    mysql shell 执行脚本 #!/bin/bash export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql-5.6/bin:/usr ...

  6. Linux 用户管理(三)

    一.userdel --delete a user account and related files -r  --remove 删除用户及家目录 二.id --print real and effe ...

  7. python向上取整 向下取整

    向上取整 ceil() 函数返回数字的向上取整整数,就是返回大于等于变量的最近的整数. ceil()是不能直接访问的,需要导入 math 模块. import math math.ceil( x ) ...

  8. Kattis - doubleclique (图论)

    From : North American Invitational Programming Contest 2018 给你一个图,以及它的补图.如果部分点在原图中是团,并且其他的所有点在补图中也是团 ...

  9. 数据结构和算法(What Why How)

    数据结构和算法是什么? 从广义上讲,数据结构就是指一组数据的存储结构.算法就是操作数据的一组方法. 从狭义上讲,是指某些著名的数据结构和算法,比如队列.堆.栈.二分查找.动态规划等. 数据结构和算法有 ...

  10. HTTP认证之摘要认证——Digest(二)

    导航 HTTP认证之基本认证--Basic(一) HTTP认证之基本认证--Basic(二) HTTP认证之摘要认证--Digest(一) HTTP认证之摘要认证--Digest(二) 在HTTP认证 ...