Article Directory
topic description
Given an array with 6 integers in it, find the maximum 24-bit time that the array can represent, output this time, and output invalid if it cannot be represented.
enter description
The input is an array of integers with six integers in the array.
The length of the input integer array is 6, no need to consider other lengths, the element value is 0 or a positive integer, and each of the 6 numbers can only be used once.
output description
The output is a time in hexadecimal format, or the string "invalid".
Remark:
The output time format is xxxxx.
Example 1 The input and output examples are only for debugging, and the background judgment data generally does not include examples
enter
[0,2,3,0,5,6]
output
23:56:00
train of thought
Ideas:
-
First, we need to get an array of 6 integers from the input, representing the set of input numbers.
-
Next, we need to perform a full permutation of this array to get all the different permutations and combinations. This can be achieved using the depth-first search (DFS) algorithm. The basic idea of DFS is to start from the first element of the array, and exchange each element with other unused elements in turn to form different permutations and combinations.
-
When doing DFS, we need to define a helper function
dfs()
to do the recursive search. in the search