spoj 147
来源:互联网 发布:形容网络发达的句子 编辑:程序博客网 时间:2024/05/18 12:01
dfs枚举真值
#include <cstdio>#include <cstring>#include <cstdlib>#include <stack>using namespace std;char s[120];bool ch[30];bool b[30];int cur[30];int len;int dfs(int m, int mm){ if(m == mm) { stack<bool> q; for(int i = len-1; i >= 0; i--) { if(s[i] >= 'a' && s[i] <= 'z') { q.push(b[cur[s[i]-'a'+1]]); } else { if(s[i] == 'C') { bool x,y; x = q.top(), q.pop(); y = q.top(), q.pop(); q.push(x && y); } else if(s[i] == 'D') { bool x,y; x = q.top(), q.pop(); y = q.top(), q.pop(); q.push(x || y); } else if(s[i] == 'I') { bool x,y; x = q.top(), q.pop(); y = q.top(), q.pop(); q.push((!x) || y); } else if(s[i] == 'E') { bool x,y; x = q.top(), q.pop(); y = q.top(), q.pop(); q.push(((!x) || y) && ((!y) || x)); } else { bool x; x = q.top(), q.pop(); q.push(!x); } } } return q.top(); } else { b[m] = true; if(dfs(m+1, mm)) { b[m] = false; return dfs(m+1, mm); } } return false;}int main(){ int n; scanf("%d",&n); while(n--) { memset(ch, false, sizeof(ch)); memset(b, false, sizeof(b)); scanf("%s",s); len = strlen(s); for(int i = len-1; i >= 0; i--) { if(s[i] >= 'a' && s[i] <= 'z') ch[s[i] - 'a'+1] = true; } int e = 1; for(int i = 1; i <= 26; i++) if(ch[i]) cur[i] = e++; if(dfs(1, e)) puts("YES"); else puts("NO"); } return 0;}
- spoj 147
- SPOJ 147真值表
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- BM算法实现源代码
- jQuery选择器之过滤选择器之内容过滤选择器
- 一种无采样电阻的功率器件保护方法
- [视频处理] 使用copy命令合并视频
- C++、GDAL创建shapefile,并向矢量文件中添加网格
- spoj 147
- 低成本MOS管下管驱动电路原理分析
- Linux上iptables防火墙的基本应用教程
- 飘逸的python - 多条件排序及itemgetter的应用
- 杭电1159-Common Subsequence
- C#学习笔记02:程序结构
- kinetis晶体谐振器到底要不要加电容和电阻
- ::Coinitialize and ::CoUninitialize
- shell笔记(三)——其他循环结构