UESTC 1307 Windy number (digital DP, Base)

Source: Internet
Author: User

Test instructions

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 would like to know the total number of windy between A and B, including A and b?

Ideas:

is to limit the number of consecutive two-digit numbers. Mainly on the issue of the number of pushes. I believe it is easy to write the transfer equation, but the problem is the leading 0 question, do not know how you count the beginning of 0, such as dp[i][0] to indicate what? If the statistic interval [0,10], the output of the dp[2][0] will be 8? (ie 02,03,04,05,06,07,08,09), in fact you forget statistics 00 and 01, because they clashed with the leading 0. So try to solve the problem.

Because the subject cannot find the source of the submission, the code out does not guarantee correctness.

1 //#include <bits/stdc++.h>2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <map>7#include <algorithm>8#include <vector>9#include <iostream>Ten #definePII pair<int,int> One #defineINF 0x7f3f3f3f A #defineLL Long Long - #defineLL unsigned long Long - using namespacestd; the Const DoublePI = ACOs (-1.0); - Const intn=Ten; - intDp[n][n], Sum[n], bit[n+5]; -  + voidpre_cal () - { +sum[1]=Ten; A      for(intI=0; i<n; i++) dp[1][i]=1; at      for(intI=2; i<n; i++)//Number of digits -     { -sum[i]+=sum[i-1]; -          for(intj=1; j<n; J + +) sum[i]+=dp[i-1][J];//does not contain a leading 0 -          for(intj=0; j<n; J + +)//start with J -         { in              for(intk=0; k<n; k++)//the next bit starts with K -                 if(ABS (J-K) >=2) todp[i][j]+=dp[i-1][k]; +         } -     } the } *  $ Panax Notoginseng intCalintN) - { thememset (bit,0,sizeof(bit)); +     intlen=0; A      while(n) the     { +bit[++len]=n%Ten; -N/=Ten; $     } $     intans=sum[len-1], i=Len; -      for(; i>0; i--) -     { the          for(intj=0; j<bit[i]; J + +)//cannot exceed Bit[i] -             if(ABS (bit[i+1]-J) >=2 )Wuyians+=Dp[i][j]; the         if(I<len && ABS (bit[i+1]-bit[i]) <2 ) -              Break;//The previous and this has constituted an illegal Wu     } -     if(i==0) ans++; About     returnans; $ } -  - intMain () - { A     //freopen ("Input.txt", "R", stdin); + pre_cal (); the     intL, R; -      while(~SCANF ("%d%d",&l,&R)) $printf"%d\n", Cal (R)-cal (l1)); the     return 0; the}
Code

UESTC 1307 Windy number (digital DP, Base)

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.