Bzoj 1026 [SCOI2009] Windy number--digit DP

Source: Internet
Author: User

Title: https://www.lydsy.com/JudgeOnline/problem.php?id=1026

Quite simple digital DP, pre-F[I][J] represents the number of I digits, the number of windy starting with J;

But do not understand why the last one to take out a special sentence ret++ wrong, and write in the loop, special i==1 on the right ...

The code is as follows:

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;inta,b,f[ the][ the],num[ the];intAbbintx) {return(x>0)? x:-x;}intGetnum (intx) {    intCnt=0;  while(x) num[++cnt]=x%Ten, x/=Ten; returnCNT;}voidinit () {intmx=Getnum (b);  for(intI=0; i<=9; i++) f[1][i]=1;  for(intI=2; i<=mx;i++)         for(intj=0; j<=9; j + +)             for(intk=0; k<=9; k++)                    if(ABB (J-K) >=2) f[i][j]+=f[i-1][k];}intCalcintx) {    intMx=getnum (x), ret=0;  for(intI=1; i<mx;i++)         for(intj=1; j<=9; j + +) ret+=F[i][j];  for(intj=1; j<num[mx];j++) ret+=F[mx][j];  for(inti=mx-1, pre;i;i--) {Pre=num[i+1]; if(i!=1)        {             for(intj=0; j<num[i];j++)                if(ABB (PRE-J) >=2) ret+=F[i][j]; }        if(i==1)//AC        {             for(intj=0; j<=num[i];j++)                if(ABB (PRE-J) >=2) ret+=F[i][j]; }        if(ABB (Num[i]-pre) <2) Break;//!    }//if (mx==1| | ABB (Num[1]-num[2]) >=2) ret++;//WA//if (ABB (num[1]-num[2)) >=2) ret++;//WA    returnret;}intMain () {scanf ("%d%d",&a,&b);    Init (); printf ("%d\n", Calc (b)-calc (A-1)); return 0;}

Bzoj 1026 [SCOI2009] Windy number--digit 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.