Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
def gen_switch(i, n):
    ret = []
    str_bin = format(i, '011b')
    for k in range(n):
        ret.append(int(str_bin[-k-1]))
    ret.reverse()
    return ret


input_line = raw_input()
splitted_line = input_line.split(" ")
n = int(splitted_line[0])
m = int(splitted_line[1])


my_mtx = []

for i in range(m):
    my_list = [0] * n
    splitted_line = raw_input().split(" ")

    for j in range(len(splitted_line)):
        if j != 0:
            my_list[int(splitted_line[j])-1] = 1

    my_mtx.append(my_list)

splitted_line = raw_input().split(" ")
my_list = []

for item in splitted_line:
    my_list.append(int(item))


count = 0

# print(my_list)

for i in range(2 ** n):
    my_switch = gen_switch(i, n)
    for j in range(m):
        my_sum = 0
        for k in range(len(my_switch)):
            my_sum = my_sum + (my_switch[k] * my_mtx[j][k])
        if my_sum % 2 != my_list[j]:
            break
        if j == m - 1:
            count = count + 1

print(count)


def gen_switch(i, n):
    ret = []
    str_bin = format(i, '011b')
    for k in range(n):
        ret.append(int(str_bin[-k-1]))
    ret.reverse()
    return ret


input_line = raw_input()
splitted_line = input_line.split(" ")
n = int(splitted_line[0])
m = int(splitted_line[1])


my_mtx = []

for i in range(m):
    my_list = [0] * n
    splitted_line = raw_input().split(" ")

    for j in range(len(splitted_line)):
        if j != 0:
            my_list[int(splitted_line[j])-1] = 1

    my_mtx.append(my_list)

splitted_line = raw_input().split(" ")
my_list = []

for item in splitted_line:
    my_list.append(int(item))


count = 0

# print(my_list)                                                                                                                                                                                                              

for i in range(2 ** n):
    my_switch = gen_switch(i, n)
    for j in range(m):
        my_sum = 0
        for k in range(len(my_switch)):
            my_sum = my_sum + (my_switch[k] * my_mtx[j][k])
        if my_sum % 2 != my_list[j]:
            break
        if j == m - 1:
            count = count + 1

print(count)

def gen_switch(i, n):
    ret = []
    str_bin = format(i, '011b')
    for k in range(n):
        ret.append(int(str_bin[-k-1]))
    ret.reverse()
    return ret


input_line = raw_input()
splitted_line = input_line.split(" ")
n = int(splitted_line[0])
m = int(splitted_line[1])


my_mtx = []

for i in range(m):
    my_list = [0] * n
    splitted_line = raw_input().split(" ")

    for j in range(len(splitted_line)):
        if j != 0:
            my_list[int(splitted_line[j])-1] = 1

    my_mtx.append(my_list)

splitted_line = raw_input().split(" ")
my_list = []

for item in splitted_line:
    my_list.append(int(item))


count = 0

# print(my_list)

for i in range(2 ** n):
    my_switch = gen_switch(i, n)
    for j in range(m):
        my_sum = 0
        for k in range(len(my_switch)):
            my_sum = my_sum + (my_switch[k] * my_mtx[j][k])
        if my_sum % 2 != my_list[j]:
            break
        if j == m - 1:
            count = count + 1

print(count)


def gen_switch(i, n):
    ret = []
    str_bin = format(i, '011b')
    for k in range(n):
        ret.append(int(str_bin[-k-1]))
    ret.reverse()
    return ret


input_line = input()
splitted_line = input_line.split(" ")
n = int(splitted_line[0])
m = int(splitted_line[1])


my_mtx = []

for i in range(m):
    my_list = [0] * n
    splitted_line = input().split(" ")

    for j in range(len(splitted_line)):
        if j != 0:
            my_list[int(splitted_line[j])-1] = 1

    my_mtx.append(my_list)

splitted_line = input().split(" ")
my_list = []

for item in splitted_line:
    my_list.append(int(item))


count = 0

# print(my_list)                                                                                                                                                                                                              

for i in range(2 ** n):
    my_switch = gen_switch(i, n)
    for j in range(m):
        my_sum = 0
        for k in range(len(my_switch)):
            my_sum = my_sum + (my_switch[k] * my_mtx[j][k])
        if my_sum % 2 != my_list[j]:
            break
        if j == m - 1:
            count = count + 1

print(count)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted