CF1340B Nastya and Scoreboard

Posted handlip

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

以上是关于CF1340B Nastya and Scoreboard的主要内容,如果未能解决你的问题,请参考以下文章

CF1340B Nastya and Scoreboard (dp 确定可行方案)

CF1340F Nastya and CBS

CF992E Nastya and King-Shamans 解题报告

CF1340D Nastya and Time Machine

CF1340D Nastya and Time Machine

CF992C Nastya and a Wardrobe