BZOJ1026: [Scoi2009]windy number [digital DP]

Source: Internet
Author: User

1026: [Scoi2009]windy number time limit:1 Sec Memory limit:162 MB
submit:6346 solved:2831
[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.

D[i][j] Indicates the number of windy for the first I bit, and the second digit of JInitialize D[1][j]=1and then move directly .Sol does not count the skyline first, then statistics skyline, if (ABS (A[i+1]-a[i]) <2) break; Note: This also does not count N is not the windy number
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespacestd;Const intn= -, inf=1e9+5;intl,r,d[n][ One];voiddp () { for(intj=0; j<=9; j + +) d[1][j]=1;  for(intI=2; i<=Ten; i++)         for(intj=0; j<=9; j + +)             for(intk=0; k<=9; k++)                if(ABS (J-K) >=2) d[i][j]+=d[i-1][k];}intSolintN) {    inta[n],len=0, ans=0;  while(n) a[++len]=n%Ten, n/=Ten; A[len+1]=0;  for(inti=len-1; i>=1; i--) for(intj=1; j<=9; j + +) ans+=D[i][j];  for(intj=1; j<a[len];j++) ans+=D[len][j]; //Skyline     for(inti=len-1; i>=1; i--){         for(intj=0; j<a[i];j++)            if(ABS (a[i+1]-J) >=2) ans+=D[i][j]; if(ABS (a[i+1]-a[i]) <2) Break; }        returnans;}intMain () {DP (); scanf ("%d%d",&l,&R); printf ("%d", Sol (r+1)-Sol (L));}

BZOJ1026: [Scoi2009]windy number [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.