二分图匹配。

先检查每个数字$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. Vue.js和angular.js区别

    Vue.js:易学 简单 指令以v.xxx 一片HTML代码配合json,在new出来Vue,js实例 个人维护项目 适用于移动端 应用超越了angular angular.js:上手难 指令以ng. ...

  2. HTML常用标签-手打抄录-来自-烟雨飘零-拜谢

    HTML常用标签及其全称 <a href="#">a 超级链接(anchor)</a>    <abbr title="abbreviati ...

  3. CS48 D BIT

    统计一个点对应的和它严格右下方的点,点对数量.由于数据规模很大,不能直接上二维的前缀和,先排一维序,然后用BIT维护前缀和即可. /** @Date : 2017-09-14 20:17:30 * @ ...

  4. 5 Techniques To Understand Machine Learning Algorithms Without the Background in Mathematics

    5 Techniques To Understand Machine Learning Algorithms Without the Background in Mathematics Where d ...

  5. GridControl详解(四)分组排序汇总

    分组: 按时间分第一组: 按性别分第二组: 显示结果: 高级设置: 将所有组展开代码:gridView1.ExpandAllGroups(); 显示结果: 自定义组名,GridView级事件 增加事件 ...

  6. [php]禁用缓存

    header("Expires: -1"); header("Cache-Control: no_cache"); header("pragma: n ...

  7. 【CodeForces】914 E. Palindromes in a Tree 点分治

    [题目]E. Palindromes in a Tree [题意]给定一棵树,每个点都有一个a~t的字符,一条路径回文定义为路径上的字符存在一个排列构成回文串,求经过每个点的回文路径数.n<=2 ...

  8. MyBatis笔记之配置输出日志并打印输出SQL语句

    1. 引入Log4J的Maven依赖: <dependency> <groupId>log4j</groupId> <artifactId>log4j& ...

  9. 分享6款国内、外开源PHP轻论坛CMS程序

    第一.Startbbs Startbbs,一款国产个人兴趣分享的轻论坛程序,采用PHP+MYSQL架构,目前版本是V1.1.5,之前我也 有搭建使用过功能还是比较简单的,默认风格比较让普通用户接受,这 ...

  10. Tinyos 第三版Make系统

    1.make系统安装 cd tools ./Bootstrap ./configure make sudo make install 2.make系统结构 3.第三版Makerules文件部分解析 # ...