如何在布尔可满足性表达式中保存和比较值?

Lou*_*s93 0 c algorithm boolean

在这样的问题, 在此输入图像描述

如果我在使用递归解决C中的问题,我必须找到满足表达式的X1,X2和X3的所有TRUE或FALSE值,我将如何比较对齐(变量是否不像X2中的那样)第一个条款)反对实际的真假值?我可以使用0和1并递归尝试所有排列,但我不确定如何实际计算这个.

K-b*_*llo 5

我不完全确定你的问题,但你有4个布尔值,可以用4位表示.通过利用积分的内部表示,您可以在for循环中进行检查以检查所有可能的组合:

for( int i = 0; i < 16; ++i ) // That's 2^4
{
    int x1 = i & 1;
    int x2 = i & 2;
    int x3 = i & 4;
    int x4 = i & 8;

    if( ( x1 || !x2 || !x3 ) && ( x1 || x2 || x4 ) )
        ... the expression holds for this combination, store it somewhere ...
}
Run Code Online (Sandbox Code Playgroud)