39 lines
938 B
C++
39 lines
938 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
typedef long long LL;
|
|
struct Node {
|
|
int number; // 对应的数字
|
|
int cnt; // 数字使用的小木棍数量
|
|
} a[6] = {{1, 2}, {2, 5}, {4, 4}, {6, 6}, {7, 3}, {8, 7}};
|
|
|
|
LL res = LONG_LONG_MAX;
|
|
/*
|
|
u 从左到右第几个数位
|
|
r 剩余木棍数量
|
|
s 已经拼接出的数字是多大
|
|
*/
|
|
void dfs(int u, int r, LL s) {
|
|
// 递归出口
|
|
if (r == 0) {
|
|
res = min(res, s);
|
|
return;
|
|
}
|
|
for (int i = 0; i < 6; i++) {
|
|
if (r >= a[i].cnt) {
|
|
if (a[i].number == 6 && u > 1)
|
|
dfs(u + 1, r - a[i].cnt, s * 10);
|
|
else
|
|
dfs(u + 1, r - a[i].cnt, s * 10 + a[i].number);
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
for (int i = 2; i <= 30; i++) {
|
|
res = LONG_LONG_MAX;
|
|
dfs(0, i, 0);
|
|
cout << "n=" << i << " number=" << res << endl;
|
|
}
|
|
|
|
return 0;
|
|
} |