Topic Link: Click to open the link
Test instructions
The oldest sequence of a number itself = each digit is a number and then the LIS
Q The number of the oldest sequence of its own in the interval ==k
Ideas:
Because the oldest sequence of its own is at most = 10 and consists of 0~9, 10 binary representations of the shape pressure indicate which numbers in the 0~9 have been used
DP[I][J] represents the number of length I, the number of number state J in the oldest sequence. As the number of queries =k, it is also saved to avoid duplication of calculations.
#include <cstdio> #include <algorithm> #include <cstring> #include <iostream>using namespace Std;typedef Long Long ll;const int N = 66;int siz[1 <<], nex[1 << 10][10]; NEX[I][J] indicates that the sequence of I states has been used, and then add the number J and make the sequence state will become the state of int bit[20], k;//because K is only 10, so the longest form of this sequence is 0~9, so with a binary means 0~9 which has been used in the LL The dp[n][1<<10][11];//dp[len][high][state][lis]; length is Len, the highest bit is high, the status of the used valid subsequence is state, and the longest ascending 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&&am P;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/=) bit[++len] = tmp% 10;return dfs (len, 0, 1, 1);} int Find_nex (int status, int num) {for (int i = num; i < ten; 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 << i++) {Siz[i] = 0;for (int j = 0; J < Ten; 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\n", cas++, Sol VE (R)-Solve (L-1));} return 0;}
HDU 4352 Xhxj ' s LIS digital DP