Hdu_5787_k-wolf Number (DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.