dfs暴搜一下就行,其实剪完枝复杂度不是很大(最深只有10层),加上输出c++也只要不到10s。
/*----------------------------------*/
/* Author : KaMtuo */
/* Email : kamtuo@qq.com */
/* Creation_time : 2022-08-08 20:06 */
/* Software : Visual Studio Code */
/*----------------------------------*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#include <vector>
#include <map>
#define endl "\n"
using std::cin;
using std::cout;
using std::max;
using std::min;
using std::sort;
using std::queue;
using std::priority_queue;
using std::vector;
using std::map;
using std::string;
const int N = 30;
const int target_num = 500;
int cnt;
vector<int> in;
void dfs(int now, int sum, int to) {
if (sum == target_num && to == 10) {
cnt ++;
for (int i = 0; i < in.size(); i ++) cout << in[i] << ' ';
cout << endl;
}
if (sum >= target_num || to >= 10) return;
for (int i = now; i <= 73; i ++) {
in.push_back(i);
dfs(i, sum + i, to + 1);
in.pop_back();
}
}
int main() {
freopen("all.txt", "w", stdout);
dfs(44, 0, 0);
cout << cnt << endl;
return 0;
}
总共177376种,以下是部分方案