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值的和 ...
随机推荐
- jQuery骨架
jQuery选择器 jQuery操作DOM jQuery中的事件与应用 jQuery的动画与特效 Ajax在jQuery中的应用 jQuery常用插件 jQuery UI插件 jQuery实用工具函数 ...
- 简单的json传送数据
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> ...
- java静态代码块、初始化块和构造方法的执行顺序
分析:当执行new Child()时,它首先去看父类里面有没有静态代码块,如果有,它先去执行父类里面静态代码块里面的内容,当父类的静态代码块里面的内容执行完毕之后,接着去执行子类(自己这个类)里面的静 ...
- 常见web服务器错误
参考地址:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5 10 Status Code Definitions ...
- [Guava学习笔记]Strings: 字符串处理
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3861502.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...
- lnmp下配置虚拟主机
一:首先熟悉几个命令 which php ---> which是通过 PATH环境变量到该路径内查找可执行文件,所以基本的功能是寻找可执行文件 whereis php ----& ...
- 查询sql语句所花时间
--1:下面这种是SQL Server中比较简单的查询SQL语句执行时间方法,通过查询前的时间和查询后的时间差来计算的: declare @begin_date datetime declare @e ...
- 简单的同步MSMQ
# 简单的同步MSMQ ```cs using System; using System.Messaging; using System.Windows.Forms; namespace MSMQEx ...
- AngularJS(16)-路由
AngularJS 路由 本章节我们将为大家介绍 AngularJS 路由. AngularJS 路由允许我们通过不同的 URL 访问不同的内容. 通过 AngularJS 可以实现多视图的单页Web ...
- GridView中的荧光棒效果
使用 ASP.NET中的GridView控件的时候会遇到这个效果,当时觉得很神奇,其实就是两句代码的事儿,可是时间长了,有点儿忘了,今天练习一下, 顺便把删除的时候弹出js中的confirm对话框也写 ...