Given a number n
(1) The integer value on the left side of the equation is 1 ~ n-1
(2) Let the sum on the left of the equation be n.
If n = 3; 1 + 1 + 1 = 3; 1 + 2 = 3;
Is there a requirement for the order on the left?
What if it’s four? There is one
2 + 1 + 1It’s still two
It’s better to search more before asking questions. There are similar questions on segmentfaulthttps://segmentfault.com/q/10…
One answer is DFS, which can output specific solutions, but the efficiency is low.
One of my answers is dynamic programming (DP), time complexity
The generating function mentioned above can also be used, but it is not convenient
If you save each case in an array?
Do you mean that the output you expect is an array, and each element is a string of the form “1 + 1 + 2 = 4”?
Use the integer array instead of the plus sign