Title Description
Spicy Chicken Konjac konjac Sol is a fool, he actually think the number is very cute!
Fortunately in his eyes, not all the numbers are moe. Only the number that satisfies "a palindrome with a length of at least 2" is Moe-that is, 101 is Moe, because 101 itself is a palindrome number, 110 is Moe, because it contains a palindrome string 11, but 102 is not Moe, 1201 is not moe.
Now Sol wants to know how many Moe numbers are in all integers from L to R.
Because the answer can be large, you only need to output the remainder of the answer to 1000000007 (10^9+7).
Input/output format
Input format:
The input contains only 1 rows and contains two integers: L, R.
Output format:
The output is only 1 lines and contains an integer, which is the answer.
Input/Output sample
Input Sample # #:Copy
1 100
Sample # # of output:Copy
10
Input Sample #:Copy
100 1000
Output Example #:Copy
253
Description
Remember that n is the number of bits in the R 10 binary.
For 10% of data, N <= 3.
For 30% of data, n <= 6.
For 60% of data, N <= 9.
For all data, n <= 1000,l < R.
Using memory search to implement digital DP
If you don't have a limit, you can remember.
The finite bit is going to go down recursively.
Also consider leading 0
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7typedefLong Longlol;8LOL f[1001][ A][ A][2],mod=1e9+7;9 Chars1[1001],s2[1001],s[1001];Tenlol DFS (intPosintPreintbefintTintKintflag) One{inti; A if(pos<0)returnT; - if(!flag&&f[pos][pre+1][bef+1][t]!=-1)returnF[pos][pre+1][bef+1][t]; - intend; theLOL cnt=0; - if(flag) end=s[pos]-'0'; - ElseEnd=9; - for(i=0; i<=end;i++) + { -Cnt+=dfs (pos-1, i,k?pre:-1, t| | ((i==pre) &&k) | | ((I==BEF) &&k), k| | (i!=0),flag&& (i==end)); +cnt%=Mod; A } at if(!flag&&k&&bef!=-1) f[pos][pre+1][bef+1][t]=CNT; - returnCNT; - } -LOL solve (Charch[]) -{inti; -memset (f,-1,sizeof(f)); in intlen=strlen (CH); - for(i=0; i<len;i++) tos[len-i-1]=Ch[i]; + while(s[len-1]=='0') len--; - returnDFS (len-1,-1,-1,0,0,1); the } * intMain () ${inti;Panax NotoginsengCin>>s1>>S2; - intlen=strlen (S1); thes1[len-1]--; + for(i=len-1; i>=0; i--) A if(s1[i]<'0') s1[i]+=Ten, s1[i-1]--; theprintf"%lld\n", (Solve (S2)-solve (S1) +mod)%Mod); +}
Luogu 3413 sac#1-Meng Number