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的更多相关文章

  1. 【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 ...

  2. SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]

    题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...

  3. 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 ...

  4. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  5. 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 ...

  6. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  7. uva 147 Dollars

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  9. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

随机推荐

  1. JAVA:二进制(原码 反码 补码),位运算,移位运算,约瑟夫问题(5)

    一.二进制,位运算,移位运算 1.二进制 对于原码, 反码, 补码而言, 需要注意以下几点: (1).Java中没有无符号数, 换言之, Java中的数都是有符号的; (2).二进制的最高位是符号位, ...

  2. 常见web服务器错误

    参考地址:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5     10 Status Code Definitions ...

  3. 1 . Robberies (hdu 2955)

    The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually g ...

  4. 使用记事本+CSC编译程序

    本次学习主要阐明.NET开发可以不使用VS,也能像Java一样使用命令窗口.但实际意义不大. 诸位看管不必太留意.(仅供留着给公司新人,树(tree)新(new)风(bee)用.) 1.新建一个文本文 ...

  5. CMD规范的函数与普通函数间调用

    /* * a.js * 普通的非cmd规范的js文件 */ function fun1(){ console.log("fun1"); //调用seajs模块中的fun1 seaj ...

  6. JQuery插件开发 - 模板

    (function($) { $.fn.PluginName = function(options) { // 创建一个默认设置对象 var defaults = { key : "Defa ...

  7. Oracle中Left join的on和where的效率差别

    假设有两个表a.b 使用on Select * from a left join b on b.col = a.col and b.col2 = ‘aa’ 使用 where Select * from ...

  8. mysql主从备份、主从切换的例子

    指定binlog(因为时通过binlog实现数据同步的) 配置完后重启数据库服务,用show master status可以看到Master信息. StepB: 在SerB的my.cnf中指定 [ht ...

  9. ADO.NET的五个主要对象

    优秀文章链接:http://www.cnblogs.com/xianspace/archive/2009/02/21/1395307.html http://www.cnblogs.com/aito/ ...

  10. 金融系列4《PUTKEY指令》

    用一个新的密钥替换一个已经存在的密钥:新密钥可以有与被替换的密钥相同的或不同的密钥版本号,但是必须与被替换的密钥有相同的密钥标识符. 用新密钥替换多个已经存在的密钥:新密钥可以有与被替换的密钥相同的或 ...