Title Link: Hdu_5787_k-wolf number
Test instructions
Give you an interval that allows you to find the number of numbers that do not have the same number in any k digits
Exercises
Because K is not big, directly to the current POS of the number of front k-1 in the line
1#include <cstdio>2#include <cstring>3 intdig[ -],len,k;4 Long Longdp[ -][ One][ One][ One][ One][2];5 6 Long LongDfsintPosintPre[],BOOLInfBOOLZe=1)7 {8 if(!pos)return 1;9 Long Long*pp=&dp[pos][pre[1]][pre[2]][pre[3]][pre[4]][ze];Ten if(!inf&& (*PP)!=-1)return*pp; One intEn=inf?dig[pos]:9; A Long Longans=0; - for(intI=0; i<=en;i++){ - intfg=0, pr[5];; the for(intj=1; j<k&&j<=len-pos&&ze==0; j + +)if(I==pre[j]) {fg=1;} - if(FG)Continue; - for(intj=1; j<=4; j + +) pr[j]=Ten; - for(intj=k-1; j>=2; j--) pr[j]=pre[j-1]; + if(i==0&&ze) pr[1]=Ten;Elsepr[1]=i; -Ans+=dfs (pos-1, Pr,inf&&i==en, (i==0&&ze)); + } A if(!inf) *pp=ans; at returnans; - } - - intMain () - { - Long LongL,r; in while(~SCANF ("%lld%lld%d",&l,&r,&k)) { -memset (dp,-1,sizeof(DP)), l--; to for(len=0; l;l/=Ten) dig[++len]=l%Ten; + intpre[5]; - for(intI=1; i<=4; i++) pre[i]=Ten; the Long LongTmp=dfs (Len,pre,1); * for(len=0; r;r/=Ten) dig[++len]=r%Ten; $ for(intI=1; i<=4; i++) pre[i]=Ten;Panax Notoginsengprintf"%lld\n", DFS (Len,pre,1)-tmp); - } the return 0; +}
View Code
Hdu_5787_k-wolf Number (DP)