Describe
Given two arrays, consisting of the number 0-9, the length is a and B, you need to use a, b two array of numbers together to get a positive integer length K (k <= a+b), the output of all possible combinations of the number of the largest one (the original array of numbers in the order cannot be changed)
Solution
\ (f_{i,j,k}\) represents the first string to the i\ position, the second string to the j\ , and a total of \ (k\)
It's poisonous.
I'm not in the Python
right position.
It's like doing a little constant optimization.
Code
def solution (line): tmp = Line.split (') a = Tmp[0].split (', ') b = tmp[1].split (', ') k = Min (len (a) + len (b), int (tmp[2])) f = [] N1 = Len (a) N2 = Len (b) f = [] for I in range (N1): A[i] = Int (A[i]) for J in Range (N2): b[j] = Int (b[j]) for I in range (n1 + 1): F.append ([]) for J in Range (N2 + 1): F[i].append ([]) for K in range (K + 1): F[i][j].append (0) for I in R Ange (1, n1 + 1): f[i][0][1] = a[i-1] for j in range (1, n2 + 1): f[0][j][1] = b[j-1] for I in range (n1 + 1): for j in range (N2 + 1): for k in range (1, K + 1): If i > 0: F[i][j][k] = max (F[i][j][k], Max (F[i-1][j][k], f[i-1][j][k-1] * + a[i-1])) If J > 0: F[i][j][k] = max (F[i][j][k], Max (F[i][j-1][k], f[i][j-1][k-1] * + b[j-1])) return f[n1][n2][k]
The maximum number of sequential combinations