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. vue中的修饰符

    Vue2.0学习笔记:Vue事件修饰符的使用   事件处理 如果需要在内联语句处理器中访问原生DOM事件.可以使用特殊变量$event,把它传入到methods中的方法中. 在Vue中,事件修饰符处理 ...

  2. java在线聊天项目1.3版设计好友列表框功能补充,因只要用户登录就发送一串新列表,导致不同客户端好友列表不同问题

    解决完毕后效果图: 好友列表Vector添加的时候进行判断,如果有相同的则不添加 int flag=0; for (int i = 0; i < names.size(); i++) { if ...

  3. 解决 cocos2dx iOS/mac 设置纹理寻址模式后纹理变黑的问题

    sprite:getTexture():setTexParameters(gl.LINEAR,gl.LINEAR,gl.REPEAT,gl.REPEAT) 在安卓设备上,设置了纹理自定义寻址模式,纹理 ...

  4. 响应者链和Hit-Test 机制

    概念: 响应者 : 对用户交互动作事件进行响应的对象.响应者链:成为处理事件的响应者的先后顺序链. 1.Hit-Test 机制 当用户触摸(Touch)屏幕进行交互时,系统首先要找到响应者(Respo ...

  5. Unity学习之路——C#相关

    1.C#数组数组定义 int[] number; float[] score; string[] names;动态初始化,借助new运算符为数组元素分配空间int[] Array = new int[ ...

  6. 【莫队】bzoj4866: [Ynoi2017]由乃的商场之旅

    莫队的一些套路 Description 由乃有一天去参加一个商场举办的游戏.商场派了一些球王排成一行.每个人面前有几堆球.说来也巧,由乃和你 一样,觉得这游戏很无聊,于是决定换一个商场.另一个商场是D ...

  7. Livid : 在 26 岁时写给 18 岁的自己

    转载自: https://livid.v2ex.com/essays/2012/01/24/a-letter-from-26-to-18.html 在 26 岁时写给 18 岁的自己 Jan 24, ...

  8. vsftpd服务安装与虚拟用户配置

    vsftpd的全名是“Very secure FTP Daemon” 一.安装vsftpd安装db4-util用于生成认证文件 yum -y install db4-utils 安装vsftpd yu ...

  9. PHP数组函数 array_multisort() ----对多个数组或多维数组进行排序

    PHP中array_multisort可以用来一次对多个数组进行排序,或者根据某一维或多维对多维数组进行排序. 关联(string)键名保持不变,但数字键名会被重新索引. 输入数组被当成一个表的列并以 ...

  10. OpenCV中的绘图函数

    OpenCV可以用来绘制不同的集合图形,包括直线,矩形,圆,椭圆,多边形以及在图片上添加文字.用到的绘图函数包括 cv2.line(),cv2.circle(),cv2.rectangle() ,cv ...