#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
int h[20];
int dfs(vector<int> &res)
{
int sum = 0, maxx = -1, ans = -1;
for (int i = 0; i <= 9; i ++)
{
if (maxx < h[i])
{
maxx = h[i];
ans = i;
}
sum += h[i];
}
if (sum == 0) return 1;
sum -= maxx;
if (maxx > sum + 1) return 0;
if (maxx == sum + 1)
{
if (ans == 0 && res.empty()) return 0;
else
{
res.push_back(ans);
h[ans] --;
}
}else
{
int u = res.size() == 0 ? 1 : 0;
int k = u == 1 ? -1 :res.back();
for (int i = u; i <= 9; i ++)
{
if (h[i] && i != k)
{
res.push_back(i);
h[i] --;
break;
}
}
}
return dfs(res);
}
int main()
{
int sum = 0;
for (int i = 0; i <= 9; i ++)
{
cin >> h[i];
sum += h[i];
}
if (h[0] == 1 && sum == 1)
{
cout << 0 << endl;
return 0;
}
vector<int> res;
if (dfs(res))
{
if (res.size() == 0) cout << -1 << endl;
else
{
for (auto x:res) cout << x ;
}
}
else cout << -1 ;
return 0;
}
#1002. 一个小整数
最新推荐文章于 2024-11-11 19:42:06 发布