"BZOJ-1026" Windy digital DP

Source: Internet
Author: User

1026: [Scoi2009]windy number time limit:1 Sec Memory limit:162 MB
submit:5230 solved:2353
[Submit] [Status] [Discuss] Description

Windy defines a windy number. A positive integer that does not contain a leading 0 and the difference of at least 2 of the adjacent two digits is called the windy number. Windy want to know,
What is the total number of windy between A and B, including A and b?

Input

Contains two integers, A B.

Output

An integer

Sample Input"Input Sample One"
1 10
"Input Sample Two"
theSample Output"Output Example One"
9
"Output Example II"
-HINT

"Data size and conventions"

100% data, meet 1 <= A <= B <= 2000000000.

SourceSolution

Digital DP Bare Topic

F[I][J] Indicates the number of satisfied conditions where the highest bit of the number of bits is J

Just transfer it, and pay attention when you're 0.

Code
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;intL,r;intf[ -][Ten];voidprework () { for(intI=0; i<=9; i++) f[1][i]=1;  for(intI=2; i<=Ten; i++)         for(intj=0; j<=9; J + +)             for(intk=0; k<=9; k++)                if(ABS (J-K) >=2) f[i][j]+=f[i-1][k];}intCalc (intx) {    if(x==0)return 0; intdigit[ One],len=0, ans=0;  while(x) {digit[++len]=x%Ten; X/=Ten;}  for(intI=1; i<len; i++)         for(intj=1; j<=9; J + +) ans+=F[i][j];  for(intI=1; i<=digit[len]-1; i++) ans+=F[len][i];  for(inti=len-1; i>=1; i--)        {             if(i==1&& ABS (digit[i+1]-digit[i]) >=2) ans++;  for(intj=0; j<=digit[i]-1; J + +)                if(ABS (digit[i+1]-J) >=2) ans+=F[i][j]; if(ABS (digit[i+1]-digit[i]) <2) Break; }    returnans;}intMain () {scanf ("%d%d",&l,&R);    Prework (); printf ("%d\n", Calc (R)-calc (l1)); return 0;} 

SB-digit DP series: Water is no longer water ...

"BZOJ-1026" Windy digital 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.