ZOJ 3954 Seven-Segment Display (预处理)
来源:互联网 发布:淘宝改标题 编辑:程序博客网 时间:2024/05/29 04:11
解题思路
首先考虑将 9 个数字所表示的所有可能字符串按状压的形式表示成 long long
类型的长整数。例如当 1~9 分别被表示成串 {“1001111”,”0010010”,”0000110”,”1001100”,”0100100”,”0100000”,”0001111”,”0000000”,”0000100”} 时,其对应的长整数为
鉴于题意中表述的 a~g
可互相交换,故对于每组 a~g
表示的位置不同, 1~9 共有
对于每次 input ,同样按照上述操作将其用长整数表示,同时判断是否存在该长整数。总复杂度为
代码
#include<bits/stdc++.h>using namespace std;set<long long> st;string s[10] = {"1001111","0010010","0000110","1001100","0100100","0100000","0001111","0000000","0000100"};char k[10];int num[10];void dfs(int idx, long long tot){ if(idx == 9){ st.insert(tot); return; } for(int i=0;i<2;i++) dfs(idx+1, tot*128 + num[idx]*i);}void init(){ int arr[7] = {0, 1, 2, 3, 4, 5, 6}; do { for(int i=0;i<9;i++) { num[i] = 0; for(int j=0;j<7;j++) (num[i] *= 2) += s[i][ arr[j] ]=='1'?1:0; } dfs(0, 0); } while(next_permutation(arr, arr+7));}int main(){ init(); int T, n, x; scanf("%d",&T); while(T--) { scanf("%d",&n); memset(num, 0, sizeof(num)); for(int i=0;i<n;i++) { scanf("%d %s",&x, k); for(int j=0;j<7;j++) (num[x]*=2) += (k[j]=='1'?1:0); } long long tot = 0; for(int i=1;i<=9;i++) (tot *= 128) += num[i]; if(st.find(tot) != st.end()) printf("YES\n"); else printf("NO\n"); }}
0 0
- ZOJ 3954 Seven-Segment Display (预处理)
- ZOJ 3954 Seven-Segment Display (预处理/状态压缩)
- ZOJ 3954 Seven-Segment Display
- ZOJ 3954 Seven-Segment Display
- ZOJ 3954 Seven-Segment Display
- ZOJ Seven Segment Display
- ZOJ 3954 Seven-Segment Display(思维)
- zoj 3954 Seven-Segment Display 思维
- zoj 3954 Seven-Segment Display(暴力枚举)
- zoj 3954 Seven-Segment Display 位运算
- ZOJ 3962 Seven Segment Display
- 【ZOJ 3962 Seven Segment Display】
- ZOJ-3954-Seven-Segment Display【17th浙大校赛】
- ZOJ 3962 Seven Segment Display(数位dp)
- ZOJ 3962 Seven Segment Display(*数位DP 总结)
- ZOJ 3962 Seven Segment Display (数位 DP)
- ZOJ 3962Seven Segment Display(数位dp)
- ZOJ 3962Seven Segment Display (数位DP)
- 线程安全
- 详解Windows下运用Docker部署Node.js开发环境
- eclipse 配置远程调试
- Cornerstore版本回退
- 关于The origin server did not find a current representation for the target resource …………
- ZOJ 3954 Seven-Segment Display (预处理)
- Windows、Office2010,2013激活神器HEU_KMS_Activator_v7.8.6
- 【iOS开发】 jenkins 指定gitlab上的源码时,提示无权限
- JAVA单例模式
- 面向对象:ATM的问题陈述、词汇表和领域类图
- Zoj 3956 Course Selection System (01背包)
- 【MATLAB】MATLAB的基础知识
- 最小生成树
- 树状数组和线段树(未完)