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. hdu2457

    AC自动机+DP #include <cstdio> #include <queue> #include <cstring> using namespace std ...

  2. PHP带重试功能的curl

    2016年1月13日 10:48:10 星期三 /** * @param string $url 访问链接 * @param string $target 需要重试的标准: 返回结果中是否包含$tar ...

  3. c++ 引用和指针

    1.引用 程序把引用和它的初始值绑定在一起,而不是将初始值拷贝给引用.一旦初始化完成,引用将和它的初始值对象一直绑定在一起.因为无法令引用重新绑定到另外一个对象,因此引用必须初始化. int ival ...

  4. Selenium 模拟人输入

    public static void type(WebElement e,String str) throws InterruptedException { String[] singleCharac ...

  5. jQuery修改页面元素的属性

    作为一个后台开发者,在web开发的时候会常常遇到修改前台页面的属性的问题.这两天我发现jQuery的$("#id").attr("prop","值&q ...

  6. WebLogic部署

    1.抓取解压WAR包,放在相应目录下 2.登录部署,激活 http://jingyan.baidu.com/article/c74d6000650d470f6b595d72.html Linux环境中 ...

  7. [第三方]SCNetworkReachability 获取网络状态控件使用方法

    用Cocoa Pods导入控件以后 直接导头文件 复制以下代码 [SCNetworkReachability host:@"github.com" reachabilityStat ...

  8. 编译QtAV工程库

    去https://github.com/wang-bin/QtAV下载源代码 去https://sourceforge.net/projects/qtav/files/depends/QtAV-dep ...

  9. 数据结构之AVL树

    AVL树是高度平衡的而二叉树.它的特点是:AVL树中任何节点的两个子树的高度最大差别为1. 旋转 如果在AVL树中进行插入或删除节点后,可能导致AVL树失去平衡.这种失去平衡的可以概括为4种姿态:LL ...

  10. mysql入门语句10条

    1,连接数据库服务器 mysql  -h host   -u root   -p  xxx(密码) 2,查看所有库 show databases; 3,选库 use 库名 4,查看库下面的表 show ...