因为每个数只能用一次,所以可以类似回溯的算法,或者更像是 DFS 的方法搜全部可能的解决方案即可 #include <iostream> #include <vector> using namespace std; void backtrace(int n, int m, int start, int& count) { if (m == 0) { count++; return; } if (m < 0) return; if (m - start < 0) return; ...