CF1340B Nastya and Scoreboard
作者:互联网
题目
给你 \(n\) 个用于显示单个数字的屏幕,一个屏幕由 7 条线段组成,所有的屏幕按顺序排列。已知每个屏幕初始时有哪些线段是亮的,求恰好再点亮 \(k\) 条线段之后,这些屏幕组成的数字最大为多少。
数据范围
\(n,k \le 2 \cdot 10^3\)
限制
时间:1s
空间:256M
代码
# include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 5;
int n, m;
char a[MAXN];
char dp[MAXN][MAXN];
char mask[10] = {119, 36, 93, 109, 46, 107, 123, 37, 127, 111};
int main()
{
scanf("%d %d", &n, &m);
char s[MAXN];
for (int i = 1; i <= n; ++i)
{
scanf("%s", s);
for (int j = 0, k = 1; j < 7; ++j, k *= 2)
{
a[i] += (s[j] - '0') * k;
}
}
dp[n][m] = 1;
for (int i = n - 1; i >= 0; --i)
{
for (int j = 0; j < 10; ++j)
{
if ((mask[j] | a[i + 1]) == mask[j])
{
int nseg = __builtin_popcount(mask[j] ^ a[i + 1]);
for (int k = nseg; k <= m; ++k)
{
dp[i][k - nseg] |= dp[i + 1][k];
}
}
}
}
if (!dp[0][0])
{
printf("-1");
return 0;
}
int nused = 0;
for (int i = 1; i <= n; ++i)
{
for (int j = 9; j >= 0; --j)
{
if ((mask[j] | a[i]) == mask[j])
{
int nseg = __builtin_popcount(mask[j] ^ a[i]);
if (nused + nseg <= m && dp[i][nused + nseg])
{
nused += nseg;
printf("%d", j);
break;
}
}
}
}
return 0;
}
标签:int,mask,Scoreboard,char,MAXN,nseg,Nastya,CF1340B,屏幕 来源: https://www.cnblogs.com/Handlip/p/13047269.html