spoj 147
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 1182】 SORTBIT - Sorted bit squence (数位DP)
SORTBIT - Sorted bit squence no tags Let's consider the 32 bit representation of all integers i from ...
- SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]
题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
- uva 147 Dollars
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- SPOJ bsubstr
题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...
- 【SPOJ 7258】Lexicographical Substring Search
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...
随机推荐
- 以OpenGL方式运行Unity
Unity在Windows上默认以DirextX的方式运行,在MacOS和Linux上默认以OpenGl的方式运行, 如果希望在Windows上以OpenGL的方式运行可以在命令行中输入 -force ...
- 7款经典炫酷的HTML5/jQuery动画应用示例及源码
jQuery是一款普遍受前端开发者欢迎的Javascript框架,但是开发者貌似更关注jQuery开发的插件,海量的jQuery插件让前端开发者非常方便.HTML5的加入让jQuery这个家族更加丰富 ...
- Spring AOP整理
示例展示 AOP(Aspect Oriented Programming),是面向切面编程的技术.AOP基于IoC基础,是对OOP的有益补充.AOP之所以能得到广泛认可,主要是因为它将应用系统拆分分了 ...
- 杭电ACM2058--The sum problem
http://acm.hdu.edu.cn/showproblem.php?pid=2058 以为简单的穷举就完了,结果是一直Time Limit Exceeded.. 这是代码: #include ...
- 链表的创建、测长、排序、插入、逆序的实现(C语言)
#include <stdio.h> #define END_elem 0 struct node { int date; struct node * next; }; //链表创建 no ...
- 转帖:使用TortoiseGit处理代码冲突
原址:http://www.cnblogs.com/jason-beijing/p/5718190.html 场景一 user0 有新提交 user1 没有pull -> 写新代码 -&g ...
- qt QLabel 显示网络图片
在网上试了很多代码都不能使用,自己写了写代码. 直接上代码 Codevoid QMusicLogo::setNetworkPic(const QString &szUrl) { QUrl ur ...
- Linux美化——终端提示符
1. PS1变量简介[1] PS1是Linux终端用户的一个环境变量,用来说明命令行提示符的设置. 可以使用 man bash命令查看bash手册,找到该变量支持的特殊字符,以及这些特殊字符的意义: ...
- 一步一步学ZedBoard & Zynq(四):基于AXI Lite 总线的从设备IP设计
本帖最后由 xinxincaijq 于 2013-1-9 10:27 编辑 一步一步学ZedBoard & Zynq(四):基于AXI Lite 总线的从设备IP设计 转自博客:http:// ...
- ASP.NET MVC + EF 利用存储过程读取大数据,1亿数据测试很OK
看到本文的标题,相信你会忍不住进来看看! 没错,本文要讲的就是这个重量级的东西,这个不仅仅支持单表查询,更能支持连接查询, 加入一个表10W数据,另一个表也是10万数据,当你用linq建立一个连接查询 ...