K-wolf Number


Problem Description
 
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,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≤5

 
Output
 
For each test case output a line contains an integer.
 
Sample Input
 
1 1 2
20 100 5
 
Sample Output
 
1
72
 
题意
  询问 [L,R] 间有多少个数 满足 连续k位数都不相同
题解
  数位DP
  传递 前 k-1 分别是什么
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int N = 1e5+, M = 6e4+, mod = 1e9+, inf = 1e9+;
typedef long long ll; ll L,R;
ll k,d[N],K; ll dp[][][][][];
bool vis[][][][][]; ll dfs(int dep,int f,int now[],int bo) {
int x = now[], y = now[], z = now[], e = now[];
if(dep < ) return ;
if(f&&vis[dep][x][y][z][e]) return dp[dep][x][y][z][e];
if(f) { vis[dep][x][y][z][e] = true;
ll& ret = dp[dep][x][y][z][e]; for(int i = ; i <= ; ++i) {
int OK = ;
for(int j = ; j < k-; ++j) if(now[j] == i) {OK = ; break;}
if(OK == ) continue;
if(!bo && !i) ret += dfs(dep-,f,now,bo);
else {
int tmpnow[];
for(int j = ; j <= ; ++j) tmpnow[j] = now[j+];
tmpnow[] = ;
tmpnow[k-] = i;
ret += dfs(dep-,f,tmpnow,bo||i);
}
}
return ret; }else {
ll ret = ;
for(int i = ; i <= d[dep]; ++i) { int OK = ;
for(int j = ; j < k-; ++j) if(now[j] == i) {OK = ; break;}
if(OK == ) continue;
if(!bo && !i) ret += dfs(dep-,i<d[dep],now,bo);
else { int tmpnow[];
for(int j = ; j <= ; ++j) tmpnow[j] = now[j+];
tmpnow[] = ;
tmpnow[k-] = i;
ret += dfs(dep-,i<d[dep],tmpnow,bo||i);
} }
return ret;
}
} ll solve(ll x) {
//if(x < 0) return 0;
memset(vis,false,sizeof(vis));
memset(dp,,sizeof(dp));
int len = ;
while(x) {
d[len++] = x % ;
x /= ;
}
int now[];
for(int i = ; i <= ; ++i) now[i] = ;
return dfs(len-,,now,);
} int main()
{ while(~scanf("%I64d%I64d%I64d",&L,&R,&k)) {
//K = pre[k];
printf("%I64d\n",solve(R) - solve(L-));
} /* ll x;
while(~scanf("%I64d%d",&x,&k)) {
K = pre[k];
printf("%I64d\n",solve(x));
}
*/ }

HDU 5787 K-wolf Number 数位DP的更多相关文章

  1. 多校5 HDU5787 K-wolf Number 数位DP

    // 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...

  2. HDU.4352.XHXJ's LIS(数位DP 状压 LIS)

    题目链接 \(Description\) 求\([l,r]\)中有多少个数,满足把这个数的每一位从高位到低位写下来,其LIS长度为\(k\). \(Solution\) 数位DP. 至于怎么求LIS, ...

  3. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  4. HDU 3709 Balanced Number (数位DP)

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  5. HDU 5179 beautiful number 数位dp

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...

  6. hdu 5898 odd-even number(数位dp)

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

  7. HDU 5898 odd-even number (数位DP) -2016 ICPC沈阳赛区网络赛

    题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的 ...

  8. 2017"百度之星"程序设计大赛 - 复赛1005&&HDU 6148 Valley Numer【数位dp】

    Valley Numer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. HDU 4352 - XHXJ's LIS - [数位DP][LIS问题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

随机推荐

  1. poj 1001

    http://poj.org/problem?id=1001 这是一道高精度的运算,如果你之前有写过那种高精度的乘法的题目的话,做这个也还是比较简单的.. 思路:我是首先把小数点的位置确定下来,然后其 ...

  2. perform

    public class ArgsTest { private List <Object> args; private ArgsTestCheckPoint checkPoint; pub ...

  3. ACM/ICPC 之 昂贵的聘礼-最短路解法(POJ1062)

    //转移为最短路问题,枚举必经每一个不小于酋长等级的人的最短路 //Time:16Ms Memory:208K #include<iostream> #include<cstring ...

  4. Html之head部分详解

    随便打开一个网页,右击查看网页源代码,总能看到<head>-</head>封闭标签,在里面通常会包含5类标签:title.link.script.meta.style.这5类标 ...

  5. sql server 导出表结构

    今天准备整理下手里面几个数据库,形成一个表结构文档,方便以后维护使用. 网上找到一个脚本还不错,小小的修改就满足了我的要求,执行完SQL脚本. 在结果就能看到数据库所有表的结构,这个时候只要全选,然后 ...

  6. 用户登录流程详解 +volley(StringRequest)

    在实习期间由于要求使用volley,所以第一次开始接触volley,从一开始的迷茫陌生,到疯狂的查找各种资料,通过在项目中用到的实际问题,我想做一些总结,所以写了这篇文章.下面我将介绍我理解的用户登录 ...

  7. HDU 5884 Sort -2016 ICPC 青岛赛区网络赛

    题目链接 #include <iostream> #include <math.h> #include <stdio.h> #include<algorith ...

  8. rsync实现同步

    一.备份客户端: 1.创建/etc/rsyncd.secrets 权限配置600 (写服务器端的账户密码) 2.客户端配置文件: port=873log file=/var/log/rsync.log ...

  9. August 24th 2016 Week 35th Wednesday

    Storms make trees take deeper roots. 暴风雨能使大树的根扎得更深. If the trees already have deep roots, then the s ...

  10. August 19th 2016 Week 34th Friday

    Friends are not the people you meet at the top, they are the people who were with you at the bottom. ...