二分图匹配。

先检查每个数字$1$的个数是否满足条件,不满足直接就是无解。剩下的情况可以建立二分图,如果现在的某一列可以对应于原图的某一列,那么建边。如果二分图的最大匹配是$7$,则有解,否则误解。

#include<bits/stdc++.h>
using namespace std; int n;
int num[],g[][];
char s[][];
int c[];
int cx[], cy[];
int mk[],nx,ny; int path(int u)
{
for (int v = ; v<ny; v++)
{
if (g[u][v] && !mk[v])
{
mk[v] = ;
if (cy[v] == - || path(cy[v]))
{
cx[u] = v;
cy[v] = u;
return ;
}
}
}
return ;
} int MaxMatch()
{
int res = ;
memset(cx, -, sizeof(cx));
memset(cy, -, sizeof(cy));
for (int i = ; i<nx; i++)
{
if (cx[i] == -)
{
memset(mk, , sizeof(mk));
res = res + path(i);
}
}
return res;
} char m[][]={
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
}; void init()
{
c[]=;
c[]=;
c[]=;
c[]=;
c[]=;
c[]=;
c[]=;
c[]=;
c[]=;
} int main()
{
init(); int T;
scanf("%d",&T);
int fail;
while(T--)
{
fail=;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%s",&num[i],s[i]);
for(int i=;i<=n;i++)
{
int sum=;
for(int j=;s[i][j];j++)
{
if(s[i][j]=='') sum++;
}
if(sum!=c[num[i]]) fail=;
} if(fail)
{
printf("NO\n");
continue;
} for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
g[i][j]=;
}
} for(int i=;i<=n;i++)
{
for(int j=;s[i][j];j++)
{
for(int k=;k<m[num[i]][k];k++)
{
if(s[i][j]!=m[num[i]][k]) g[j][k]=;
}
}
} nx=,ny=; int ans = MaxMatch(); if(ans!=) printf("NO\n");
else printf("YES\n"); }
return ;
}

ZOJ 3954 Seven-Segment Display的更多相关文章

  1. ZOJ 3962 Seven Segment Display 16进制的八位数加n。求加的过程中所有的花费。显示[0,F]有相应花费。

    Seven Segment Display Time Limit: Seconds Memory Limit: KB A seven segment display, or seven segment ...

  2. ZOJ 3962 Seven Segment Display

    Seven Segment Display 思路: 经典数位dp 代码: #include<bits/stdc++.h> using namespace std; #define LL l ...

  3. zoj 3962 Seven Segment Display 数位dp

    非常好的一个题,可以比赛时想到的状态太奇葩,不方便转移,就一直没能AC. 思路:dp(i, j)表示已经考虑了前i位,前i位的和为j的贡献.如果当前的选择一直是最大的选择,那么就必须从0~下一位的最大 ...

  4. ZOJ 3962 Seven Segment Display(数位DP)题解

    题意:给一个16进制8位数,给定每个数字的贡献,问你贡献和. 思路:数位DP,想了很久用什么表示状态,看题解说用和就行,其他的都算是比较正常的数位DP. 代码: #include<iostrea ...

  5. ZOJ 3962 Seven Segment Display(数位DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目大意: 有t组数据. 给你一个n,和8位的十六进制数s ...

  6. 2017浙江省赛 E - Seven Segment Display ZOJ - 3962

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目: A seven segment display, or ...

  7. ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp

    Seven Segment Display Time Limit: 1 Second      Memory Limit: 65536 KB A seven segment display, or s ...

  8. (2017浙江省赛E)Seven Segment Display

    Seven Segment Display Time Limit: 2 Seconds      Memory Limit: 65536 KB A seven segment display, or ...

  9. ZOJ - 3962 - Seven Segment Display-17省赛-数位DP

    传送门:Seven Segment Display 题意:求一个给定区间每个数字的消耗值的和: 思路:数位DP,有点区间和的思想,还有就是这个十六进制,可以用%llx读,还是比较难的: 还有就是到最大 ...

  10. ZOJ - 3954 Seven-Segment Display 【状态标记】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3954 题意 有一块 LED 灯 然后上面有七块灯管 在显示不同数 ...

随机推荐

  1. linux shell学习五

    参考:https://www.linuxdaxue.com/ Shell函数 因为函数是脚本类语言,在执行时是逐行执行的,因此,Shell 函数必须先定义后使用. Shell 函数的定义格式如下: [ ...

  2. [DeeplearningAI笔记]序列模型2.7负采样Negative sampling

    5.2自然语言处理 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2.7 负采样 Negative sampling Mikolov T, Sutskever I, Chen K, et a ...

  3. table行拖拽

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. [Thu Summer Camp 2015]解密运算

    4104: [Thu Summer Camp 2015]解密运算 Time Limit: 10 Sec  Memory Limit: 512 MB Description 对于一个长度为N的字符串,我 ...

  5. CodeForces - 996B

    Allen wants to enter a fan zone that occupies a round square and has nn entrances. There already is ...

  6. E.Text Editor (Gym 101466E + 二分 + kmp)

    题目链接:http://codeforces.com/gym/101466/problem/E 题目: 题意: 给你s串和t串,一个数k,求t的最长前缀串在s串中出现次数不少于k. 思路: 一眼二分+ ...

  7. 【Tomcat】tomcat中server.xml配置详解

    Tomcat Server的结构图如下: 该文件描述了如何启动Tomcat Server <Server>    <Listener />    <GlobaNaming ...

  8. weblogic 配置了ssl

    jingyan.baidu.com/article/72ee561abfe531e16138dfb5.html http://blog.sina.com.cn/s/blog_7ffec3e201019 ...

  9. 每天一条linux命令(1):ls命令

    ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...

  10. Codeforces Round #455 (Div. 2)

    Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...