Define a recursive function dfs that takes the current path and the usage array as arguments.
If the current path length is equal to the length of the input array, increment the count of squareful permutations.
Iterate over the array elements and for each element that has not been used:
a. Skip the element if it's the same as the previous one and the previous one has not been used (to avoid duplicates).
b. If the current path is not empty, check if the sum of the last element in the path and the current element is a perfect square. If not, skip this element.
c. Add the current element to the path, mark it as used, and call dfs recursively.
d. Backtrack by removing the current element from the path and marking it as unused.