HDU 4352 XHXJ & #39; s LIS digital dp
Question:
The eldest son sequence of a number itself = each digit is a number and then the LIS is obtained.
Q: How many of the largest sequence of their own in the interval = k
Ideas:
Because the largest of them has a sequence of at most 10 = and ranges from 0 ~ 9, so the pressure of 10 binary represents 0 ~ 9. Which digits have been used?
Dp [I] [j] indicates the number with the length of I, and the number of the method in the number status j that appears in the largest family sequence. Because the number of queries is K, it is saved to avoid repeated computation.
# Include
# Include
# Include
Using namespace std; typedef long ll; const int N = 66; int siz [1 <10], nex [1 <10] [10]; // nex [I] [j] indicates the sequence in which the I state has been used, and then the number j is added, and the sequence state changes to int bit [20], K; // because K is only 10, the maximum length of this sequence is 0 ~ 9, so a binary value is used to represent 0 ~ 9 which of the following statements have used ll dp [N] [1 <10] [11]; // dp [len] [high] [state] [lis]; the length is len, the highest bit is high, the state of the used valid subsequence is state, and the longest rising subsequence is lisll dfs (int len, int state, bool zero, bool flag) {if (len = 0) return siz [state] = K; if (! Flag & dp [len] [state] [K]! =-1) return dp [len] [state] [K]; ll ans = 0; int end = flag? Bit [len]: 9; for (int I = 0; I <= end; I ++) ans + = dfs (len-1, (zero & I = 0 )? 0: nex [state] [I], zero & I = 0, flag & I = end); if (! Flag) dp [len] [state] [K] = ans; return ans;} ll solve (ll x) {int len = 0; for (ll tmp = x; tmp; tmp/= 10) bit [++ len] = tmp % 10; return dfs (len, 0, 1, 1);} int find_nex (int status, int num) {for (int I = num; I <10; I ++) if (status & (1 <I) return (status ^ (1 <I )) | (1 <num); return status | (1 <num) ;}int main () {memset (dp,-1, sizeof dp ); for (int I = 0; I <1 <10; I ++) {siz [I] = 0; for (int j = 0; j <10; j ++) {if (I & (1 <j) siz [I] ++; nex [I] [j] = find_nex (I, j );}} int T, Cas = 1; scanf (% d, & T); while (T --> 0) {ll l, r; cin> l> r> K; printf (Case # % d: % I64d, Cas ++, solve (r)-solve (l-1);} return 0 ;}