USETC-Windy Digital DP

Source: Internet
Author: User

Note that there is only one bit of processing of numbers (in fact, no handling) = =

Simple Digital DP

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits > #include <string> #include <iostream> #include <map> #include <cstdlib> #include <list > #include <set> #include <queue> #include <stack>using namespace std;typedef long long ll;const int    MAXN = 20;int lim[maxn],len;int num[maxn];int f[15][15][15][2];void getlim (int num) {memset (lim,0,sizeof (Lim));    len = 0;        while (num) {lim[len++] = num% 10;    Num/= 10; }}int myabs (int x) {return x < 0?-x:x;}    int dfs (int now,int prev,int maxd,int first,int bound) {int &note = F[now][prev][maxd][first];        if (now = = 0) {if (First && maxd >= 2) {return 1;    } return 0;    } if (!bound && Note! =-1) return note; int m = bound?    LIM[NOW-1]: 9,ret = 0;        for (int i = 0;i <= m;i++) {num[now-1] = i; if (first) {int nmaxd = Min (Maxd,myabs (I-prev));        RET + = DFS (now-1,i,nmaxd,1,bound && i = = m);        } else {ret + = DFS (now-1,i,maxd,i | | first,bound && i = = m);    }} if (!bound) Note = ret; return ret;}    int work (int num) {memset (f,-1,sizeof (f));    if (num <) return num;    Getlim (num); Return Dfs (len,0,11,0,1);}    int main () {int n,m;    while (scanf ("%d%d", &n,&m) = = 2) {printf ("%d\n", Work (m)-work (n-1)); } return 0;}

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: 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.