# Include <stdio. h> # include <algorithm> # include <string. h> using namespace STD; int n, m, a [505], B [505], DP [505] [505]; int LICs () {int Max, I, j; memset (DP, 0, sizeof (DP); for (I = 1; I <= N; I ++) {max = 0; For (j = 1; j <= m; j ++) {DP [I] [J] = DP [I-1] [J]; if (A [I]> B [J] & max <DP [I-1] [J]) max = DP [I-1] [J]; if (A [I] = B [J]) DP [I] [J] = MAX + 1 ;}max = 0; for (I = 1; I <= m; I ++) if (max <DP [N] [I]) max = DP [N] [I]; return Max ;}
Optimized to one dimension
# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; int A [505], B [505], DP [505], n, m; int LICs () {int I, j, Max; memset (DP, 0, sizeof (DP); for (I = 1; I <= N; I ++) {max = 0; for (j = 1; j <= m; j ++) {if (a [I]> B [J] & max <DP [J]) max = DP [J]; if (a [I] = B [J]) DP [J] = MAX + 1 ;}} max = 0; for (I = 1; I <= m; I ++) if (max <DP [I]) max = DP [I]; return Max ;}