import sys MOD = 2 def setups(total, ready): if total < ready: return if ready == 0: yield [0] * total return if total == ready: yield [1] * total return for setup in setups(total - 1, ready): yield [0] + setup for setup in setups(total - 1, ready - 1): yield [1] + setup def validate(seq): one = 0 while one < len(seq) and seq[one] != 1: one += 1 if one == len(seq): return True zero = one while zero < len(seq) and seq[zero] != 0: zero += 1 if zero == len(seq): return True one = zero while one < len(seq) and seq[one] != 1: one += 1 if one == len(seq): return True return False def apply(seq, orders): for o in range(0, len(orders), 2): if seq[orders[o] - 1] and not seq[orders[o + 1] - 1]: seq[orders[o] - 1] = 0 seq[orders[o + 1] - 1] = 1 return seq if __name__ == "__main__": data = tuple(int(x) for x in sys.stdin.read().split()) soldiers = data[0] orders = data[1] order = data[2:] for s in range(1, soldiers + 1): count = 0 for setup in setups(soldiers, s): count = (count + validate(apply(setup, order))) % MOD print(count, end=" ")
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import sys MOD = 2 def setups(total, ready): if total < ready: return if ready == 0: yield [0] * total return if total == ready: yield [1] * total return for setup in setups(total - 1, ready): yield [0] + setup for setup in setups(total - 1, ready - 1): yield [1] + setup def validate(seq): one = 0 while one < len(seq) and seq[one] != 1: one += 1 if one == len(seq): return True zero = one while zero < len(seq) and seq[zero] != 0: zero += 1 if zero == len(seq): return True one = zero while one < len(seq) and seq[one] != 1: one += 1 if one == len(seq): return True return False def apply(seq, orders): for o in range(0, len(orders), 2): if seq[orders[o] - 1] and not seq[orders[o + 1] - 1]: seq[orders[o] - 1] = 0 seq[orders[o + 1] - 1] = 1 return seq if __name__ == "__main__": data = tuple(int(x) for x in sys.stdin.read().split()) soldiers = data[0] orders = data[1] order = data[2:] for s in range(1, soldiers + 1): count = 0 for setup in setups(soldiers, s): count = (count + validate(apply(setup, order))) % MOD print(count, end=" ") |