D. Nastya and Scoreboard

链接:https://codeforces.ml/contest/1341/problem/C

Denis, who managed to buy flowers and sweets (you will learn about this story in the next task), went to a meeting with Nastya to invite her to become a couple. And so, they sit together in a cafe, chatting. Denis finally offers to be them together, but ... Nastya doesn't give any answer.

The poor boy was very upset due to that. He was so sad that he kicked some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 77 segments, which can be turned on or off to display different numbers. The picture shows how all 1010 decimal digits are displayed:

After the kick, some sticks stopped working, that is, some sticks might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Let exactly kk sticks break and we know which sticks are working now. Denis came up with the question: what is the maximum number that can burn on the board if you turn on exactly kk sticks (which are off now)?

It is allowed that the number includes leading zeros.

Input

The first line contains integer nn (1≤n≤2000)(1≤n≤2000)  — the number of digits on scoreboard and kk (0≤k≤2000)(0≤k≤2000)  — the number of sticks that stopped working.

The next nn lines contain one binary string of length 77, the ii-th of which encodes the ii-th digit of the scoreboard.

Each digit on the scoreboard consists of 77 sticks. We number them, as in the picture below, and let the ii-th place of the binary string be 00 if the ii-th stick is not glowing and 11 if it is glowing. Then a binary string of length 77 will specify which sticks glowing.

Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 00 to 99 inclusive.

Output

Print a single number consisting of nn digits  — the maximum number that can be obtained if you turn on exactly kk sticks or −1−1, if it is impossible to turn on exactly kk sticks so that some sort of sequence appears on the scoreboard digits.

Examples

input

Copy

1 7
0000000

output

Copy

8

input

Copy

2 5
0010010
0010010

output

Copy

97

input

Copy

3 5
0100001
1001001
1010011

output

Copy

-1

Note

In the first test, we are obliged to include all 77 sticks and get one 88 digit on the scoreboard.

In the second test, we have sticks turned on so that units are formed. For 55 of additionally included sticks, you can get the numbers 0707, 1818, 3434, 4343, 7070, 7979, 8181 and 9797, of which we choose the maximum  — 9797.

In the third test, it is impossible to turn on exactly 55 sticks so that a sequence of numbers appears on the scoreboard.

代码:

#include<bits/stdc++.h>
using namespace std;
char num[10][8]={"1110111","0010010","1011101","1011011",
"0111010","1101011","1101111","1010010","1111111","1111011"};
long long n,k,flag=0;
long long al[2005][2005]={0};
char a[2005][8];
long long ans[2005];
void dfs(long long x)
{
	if(x==n) 
	{
		if(k==0) 
		{
			for(int i=0;i<n;i++) 
			cout<<ans[i];
			cout<<endl;
			flag=1;
		}
		return;
	}
	for (int i=9;i>=0;i--)
	{
		long long b=1,t=0;
		for(int j=0;j<7;j++)
		{
			if(a[x][j]=='1'&&num[i][j]=='0')
			{
				b=0;
				break;
			}
			else if(a[x][j]=='0'&&num[i][j]=='1') 
			t++;
		}
		if(b!=0&&k>=t&&al[x][k-t]==0)
		{
			al[x][k-t]=1;
			ans[x]=i;
			k-=t;
			dfs(x+1);
			if(flag==1) 
			return;
			k+=t;
		}
	}
}
int main()
{
	cin>>n>>k;
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dfs(0);
	if(flag==0) 
	cout<<"-1"<<endl;
	return 0;
}

 

全部评论

相关推荐

小时候觉得老师是很伟大的职业&nbsp;感觉老师都是人中龙凤才能当&nbsp;后来考入大学&nbsp;发现以前的老同学也是公费师范生了&nbsp;他们什么样什么人品&nbsp;我还不清楚吗&nbsp;只能希望他们以后也会有改变&nbsp;要不纯属耽误孩子&nbsp;实习之后发现&nbsp;有的领导&nbsp;能当上领导也可能运气成分很多&nbsp;自己决策方面很差&nbsp;分配给属下的东西自己也说不明白&nbsp;&nbsp;前些年那些明星&nbsp;各种塌房&nbsp;少林寺大师都能有情人和孩子&nbsp;越长大越发现世界就是个草台班子&nbsp;以前对不懂的东西有一层羡慕的滤镜&nbsp;接触之后发现就不是那回事了
RazerYang:其实也是幸存者偏差,你只关注草台班子的部分,所以觉得世界都是草台班子。实际上你每天能安全地从床上醒来,有稳定的天然气、自来水和电力供应,能让你吃上热乎的饭菜,能收到持续稳定的信号去刷手机,花几块钱就能坐地铁从城市的一端快速移动到另一端,花几百块就能在一天之内安全穿越整个国家,这都不是一个草台班子能实现的。燃气、水利、电力、通信、公交、民航,还有最重要的公安和国防,这些都不是草台班子能做的,有无数普通人构筑了你生活的方方面面,而你也将加入他们。
我对___祛魅了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务