悬赏,求助JT3爆空间,郁闷到原地爆炸
查看原帖
悬赏,求助JT3爆空间,郁闷到原地爆炸
617314
TigerTanWQY楼主2024/11/6 07:54
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

constexpr const int a[]{6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
constexpr const int N = 1e5 + 1;
namespace sub1 {
	const string fmt = string(N, '9');
	string s, ans;
	bool cmp(const string& A, const string& B) {
		if(A.size() != B.size())
			return A.size() < B.size();
		else
			for(int i = 0; i < A.size(); ++i)
				if(A[i] != B[i])
					return A[i] < B[i];
			return false;
	}
	void dfs(const int cnt) {
		if(cnt < 0)
			return;
		else if(cnt == 0) {
			if(s.front() != '0')
				ans = min(s, ans, cmp);
			return;
		}
		for(int i = 9; i >= 0; --i)
			if(cnt >= a[i]) {
				s += '0' + i;
				dfs(cnt - a[i]);
				s.pop_back();
			}
	}
	string work(const int n) {
		ans = fmt;
		dfs(n);
		if(ans == fmt)
			ans = "-1";
		return ans;
	}
}
string f[N + 3];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto cmp = [&](string A, string B) {
		if(A == "-1")
			return false;
		else if(A.size() != B.size())
			return A.size() < B.size();
		else
			return A < B;
	};
	for(int i = 0; i <= N; ++i)
		f[i] = "-1";
	for(int i = 9; i >= 0; --i)
		f[a[i]] = string(1, '0' + i);
	for(int i = 8; i <= N; ++i)
		for(int j = 0; j < 10; ++j)
			if(f[i - a[j]] != "-1" && f[i - a[j]] != "0")
				f[i] = min(f[i - a[j]] + char('0' + j), f[i], cmp);
	f[6] = '6';
	int _T;
	cin >> _T;
	for(int n; _T--; cout.put('\n')) {
		cin >> n;
		if(n <= 30)
			cout << sub1::work(n);
		else
			cout << f[n];
	}
	cout.flush();
	return 0;
}

2024/11/6 07:54
加载中...