K-wolf number
problem DescriptionAlice thinks an integer x was a k-wolf number, if every K adjacent digits in decimal representation of x is pairwised Diffe Rent.
Given (l,r,k), please count how many k-wolf numbers in range of [L,r].
InputThe input contains multiple test cases. There is about ten test cases.
Each test case contains three integers L, R and K.
1≤l≤R< Span id= "mathjax-span-8" class= "Mo" >≤1 e18
2 ≤k ≤5
OutputFor the test case, output a line contains an integer.
Sample Input1 1 220) 100 5
Sample Output172
Test Instructions: Ask [l,r] how many of the numbers meet the continuous K-digits are not the same
Solving: What are the k-1 before the digital DP transfer?
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")Const intN = 1e5+5, M = 6e4+5, mod = 1e9+7, INF = 1e9+ +; typedefLong Longll;ll l,r;ll k,d[n],k;ll dp[ -][ A][ A][ A][ A];BOOLvis[ -][ A][ A][ A][ A];ll DFS (intDepintFintNow[],intBo) { intx = now[0], y = now[1], z = now[2], E = now[3]; if(Dep <0)return 1; if(F&&vis[dep][x][y][z][e])returnDp[dep][x][y][z][e]; if(f) {Vis[dep][x][y][z][e]=true; ll& ret =Dp[dep][x][y][z][e]; for(inti =0; I <=9; ++i) {intOK =1; for(intj =0; J < K1; ++J)if(Now[j] = = i) {OK =0; Break;} if(OK = =0)Continue; if(!bo &&!i) ret + = DFS (dep-1, F,now,bo); Else { inttmpnow[6]; for(intj =0; J <=4; ++J) Tmpnow[j] = now[j+1]; tmpnow[5] =Ten; Tmpnow[k-2] =i; RET+ = DFS (dep-1, f,tmpnow,bo| |i); } } returnret; }Else{LL ret=0; for(inti =0; I <= D[DEP]; ++i) {intOK =1; for(intj =0; J < K1; ++J)if(Now[j] = = i) {OK =0; Break;} if(OK = =0)Continue; if(!bo &&!i) ret + = DFS (dep-1,i<D[dep],now,bo); Else { inttmpnow[6]; for(intj =0; J <=4; ++J) Tmpnow[j] = now[j+1]; tmpnow[5] =Ten; Tmpnow[k-2] =i; RET+ = DFS (dep-1, i<d[dep],tmpnow,bo| |i); } } returnret; }}ll Solve (ll x) {//if (x < 0) return 0;memset (Vis,false,sizeof(VIS)); Memset (DP,0,sizeof(DP)); intLen =0; while(x) {D[len+ +] = x%Ten; X/=Ten; } intnow[6]; for(inti =0; I <=5; ++i) Now[i] =Ten; returnDFS (len-1,0, now,0);}intMain () { while(~SCANF ("%i64d%i64d%i64d",&l,&r,&k)) {//K = pre[k];printf"%i64d\n", Solve (R)-Solve (l1)); } /*ll X; while (~SCANF ("%i64d%d", &x,&k)) {k = pre[k]; printf ("%i64d\n", Solve (x)); } */}
HDU 5787 K-wolf number digits DP