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. JS函数的length属性

    length 是函数对象的一个属性值,指该函数有多少个必须要传入的参数,那些已定义了默认值的参数不算在内,比如function(xx = 0)的length是0.. 另外在函数内部:arguments ...

  2. jQuery如何获取选中单选按钮radio的值

    使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项: 1. ...

  3. C-基础:形参char *&p与char *p

    char* &p:以引用传递的方式传指针char* p: 以值传递的方式传指针

  4. checkbox点击选中,再点击取消,并显示在文本框中

    function checkItem(e,itemId) { var item = document.getElementById(itemId); var $items = $(item); if ...

  5. IDEA项目显示树形结构

  6. 作业题:闰年 if((year%4==0&&year%100!=0)||year&400==0)

    作业题:闰年 if((year%4==0&&year%100!=0)||year&400==0)

  7. 【转】PCA算法学习_1(OpenCV中PCA实现人脸降维)

    前言: PCA是大家经常用来减少数据集的维数,同时保留数据集中对方差贡献最大的特征来达到简化数据集的目的.本文通过使用PCA来提取人脸中的特征脸这个例子,来熟悉下在oepncv中怎样使用PCA这个类. ...

  8. 编译-LAMP基于fastcgi

    前言 最近没更新新篇幅了,今天就来点干活,过多的也不说了下面着手干!干!干! 准备环境 centos7.5 apr-1.6.3.tar.gz  apr-util-1.6.1.tar.gz      h ...

  9. Ubuntu 下安装mysqlclient报错

    pip3 install mysqlclient 报错信息 问题描述: Complete output from command python setup.py egg_info: /bin/sh: ...

  10. 详解wordpress如何把文件保存到阿里云OSS上!

    自己搞了一个Wordpress的博客,装完之后一直晾着没管,最近闲来开荒.为了减小服务器的带宽.存储.CUP的压力,决定把博客中的所有文件都保存到阿里云OSS上面. 关于这个问题,自己去调用OSS的S ...