Question: The number of replies in a given range.
Ideas:
The URL Length of DP [site] [Len] site bit is Len.
You need an array to store the number of each row.
Then there is DFS, and the middle value of Len is mid.
If the value exceeds the mid value, check the symmetric number in OK to determine whether it is equal.
Can be placed in the next place.
Note that the leading 0 and the OJ must use long.
Code:
# Include "cstdlib" # include "cstdio" # include "cstring" # include "cmath" # include "queue" # include "algorithm" # include "iostream" using namespace STD; // September 24, 2014 long DP [22] [22]; int num [22], OK [22]; long DFS (INT site, int N, int zero, int f) {If (Site = 0) return 1; if (! F &&! Zero & DP [site] [N]! =-1) return DP [site] [N]; int Len = f? Num [site]: 9; long ans = 0; For (INT I = 0; I <= Len; I ++) {If (zero) {if (I = 0) ans + = DFS (site-1, n-1, zero & I = 0, F & I = Len ); else {OK [site] = I; ans + = DFS (site-1, n, zero & I = 0, F & I = Len );}} else {int mid = (n + 1)/2; If (N % 2) {If (Site = mid) ans + = DFS (site-1, n, zero & I = 0, F & I = Len); else if (site> mid) {OK [site] = I; ans + = DFS (site-1, n, zero & I = 0, F & I = Len );} else {If (OK [n + 1-site] = I) ans + = DFS (site-1, n, zero & I = 0, F & I = Len) ;}} else {If (site> mid) {OK [site] = I; ans + = DFS (site-1, n, zero & I = 0, F & I = Len);} else {If (OK [n + 1-site] = I) ans + = DFS (site-1, n, zero & I = 0, F & I = Len) ;}}} if (! F &&! Zero) DP [site] [N] = ans; return ans;} long solve (long x) {int CNT = 0; while (X) {num [++ CNT] = x % 10; X/= 10;} return DFS (CNT, CNT, 1,1);} int main () {int t, CAS = 1; CIN> T; memset (DP,-1, sizeof (DP); While (t --) {long X, Y; scanf ("% LLD", & X, & Y); If (x> Y) Swap (x, y); printf ("case % d: % LLD \ n ", CAS ++, solve (y)-solve (x-1);} return 0;} // September 24, 2014 11:26:45
[Digital DP] lightoj 1205 palindromic numbers