BZOJ1026: [Scoi2009]windy number

Source: Internet
Author: User

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% of the data, meet 1 <= A <= B <= 2000000000

Topic Portal

Say Blog Park this link is a bit ugly ...

Change a new environment, learn something new--Digital DP

The first time to do this kind of problem is still very difficult to do,% of the puzzle bar, no problem can not live series

We set F[I][J] to represent the I-bit, the maximum number of J is the number of windy, then I can think of the equation: F[i][j]=sigma (f[i-1][k]) (ABS (K-J) >=2)

But we ask for a number ah, then we have to dismantle, open, for each one to record can

The code is as follows (feel the code speaks more clearly than I say):

#include <cstdio>#include<cstring>#include<cmath>#include<cstdlib>using namespacestd;intf[ -][ -],a[110000];typedefLong Longll;voiddp () { for(intI=0; i<=9; i++) f[1][i]=1;  for(intI=2; i<= A; 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];} ll Get_a (ll x) {ll len=0;  while(x) {a[++len]=x%Ten; X/=Ten; }    returnLen;} ll Findans (ll Len) {ll ans=0;  for(intI=1; i<len;i++)         for(intj=1; j<=9; j + +) ans+=F[i][j];  for(intI=1; i<a[len];i++) ans+=F[len][i];  for(inti=len-1; i>=1; i--)    {         for(intj=0; j<a[i];j++)        if(ABS (a[i+1]-J) >=2) ans+=F[i][j]; if(ABS (a[i+1]-a[i]) <2) Break; }    returnans;}intMain () {memset (F,0,sizeof(f)); intx, y; scanf ("%d%d",&x,&y); if(x>y) {inttt=x;x=y;y=tt;}    DP (); ll Lena=get_a (x), ansa=Findans (Lena); ll LenB=get_a (++y), ansb=Findans (LENB); printf ("%lld\n", ansb-ansa); return 0;}

By_lmy

BZOJ1026: [Scoi2009]windy number

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.