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. JavaScript实用的例子

    ---恢复内容开始--- 1.发送验证码 <input id="send" type="button" value="发送验证码"&g ...

  2. javaweb基础(8)_HttpServletResponse生成验证码

    一.HttpServletResponse常见应用——生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedImage类,

  3. Url Rewrite 重写

    前几天看到园子里一篇关于 Url 重写的文章<获取ISAPI_Rewrite重写后的URL>, URL-Rewrite 这项技术早已不是一项新技术了,这个话题也已经被很多人讨论过多次.搜索 ...

  4. C# Dictionary 的几种遍历方法,排序

    Dictionary<string, int> list = new Dictionary<string, int>(); list.Add(); //3.0以上版本 fore ...

  5. 『jQuery』.html(),.text()和.val()的概述及使用--2015-08-11

    如何使用jQuery中的.html(),.text()和.val()三种方法,用于读取,修改元素的html结构,元素的文本内容,以及表单元素的value值的方法   本节内容主要介绍的是如何使用jQu ...

  6. 学习笔记(四): Representation:Feature Engineering/Qualities of Good Features/Cleaning Data/Feature Sets

    目录 Representation Feature Engineering Mapping Raw Data to Features Mapping numeric values Mapping ca ...

  7. 【费用流】loj#545. 「LibreOJ β Round #7」小埋与游乐场

    好像现在看来这个缩点的思路挺清晰啊 题目描述 有两个非负整数组成的可重集合 $A$ 和 $B$. 现在你可以对 $A$ 中至多 $k$ 个元素进行操作.操作方法为:设你准备操作且未被操作过的 $A$ ...

  8. python爬虫: 豆瓣电影top250数据分析

    转载博客 https://segmentfault.com/a/1190000005920679 根据自己的环境修改并配置mysql数据库 系统:Mac OS X 10.11 python 2.7 m ...

  9. vue渲染函数&JSX

    Vue推荐在绝大多数情况下使用template来创建你的HTML.然而在一些场景中,你真的需要JavaScript的完全编程能力,这时你可以使用render函数,它比template跟接近编译器. 虚 ...

  10. Python开发环境与开发软件的安装

    Python开发的必要因素: 开发软件:PyCharm 社区版 PyCharm安装过程: 首先去官网下载:(链接为:  https://www.jetbrains.com/pycharm/downlo ...