题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
小蓝要用七段码数码管来表示一种特殊的文字。
上图给出了七段码数码管的一个图示,数码管中一共有 77 段可以发光的二 极管,分别标记为 a, b, c, d, e, f, ga,b,c,d,e,f,g。
小蓝要选择一部分二极管(至少要有一个)发光来表达字符。在设计字符 的表达时,要求所有发光的二极管是连成一片的。
例如:bb 发光,其他二极管不发光可以用来表达一种字符。
例如 cc 发光,其他二极管不发光可以用来表达一种字符。这种方案与上 一行的方案可以用来表示不同的字符,尽管看上去比较相似。
例如:a, b, c, d, ea,b,c,d,e 发光,f, gf,g 不发光可以用来表达一种字符。
例如:b, fb,f 发光,其他二极管不发光则不能用来表达一种字符,因为发光 的二极管没有连成一片。
请问,小蓝可以用七段码数码管表达多少种不同的字符?
题解:首先将七段标成1~7(离散数学),然后有边变e[ ][ ]为1,两次的dfs(这个灯亮了dfs进去,把它弄灭再dfs,所以是写两个dfs)
VSCODE:
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// . ' \| |// `.
// / \||| : |||// \/\
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// .............................................
// 佛祖保佑 一发AC入魂 永无BUG
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
// a b c d e f g
// 1 2 3 4 5 6 7
int fa[100];
int e[10][10];
int st[10];
void init(){
for(int i=1;i<=100;i++)fa[i]=i;
}
int find(int x){
if(x==fa[x])return x;
else return fa[x]=find(fa[x]);
}
void merge(int x,int y){
int xx=find(x);
int yy=find(y);
if(xx!=yy)fa[xx]=yy;
}
int ans;
void dfs(int index){
if(index==8){
init();//初始化
for(int i=1;i<=7;i++){
for(int j=1;j<=7;j++){
if(e[i][j]&&st[i]&&st[j]){
merge(i,j);
}
}
}
int cnt=0;
for(int i=1;i<=7;i++){
if(st[i]&&fa[i]==i)cnt++;
}
if(cnt==1)ans++;
return;
}
st[index]=1;
dfs(index+1);
st[index]=0;
dfs(index+1);
}
int main()
{
e[1][2]=e[1][6]=1;
e[2][1]=e[2][7]=e[2][3]=1;
e[3][2]=e[3][7]=e[3][4]=1;
e[4][3]=e[4][5]=1;
e[5][4]=e[5][6]=e[5][7]=1;
e[6][1]=e[6][5]=e[6][7]=1;
e[7][6]=e[7][2]=e[7][5]=e[7][3]=1;
dfs(1);
cout<<ans;
}