Logic design

2.9

11 votes
Introduction, Machine Learning, Graphs, Optimization, Algorithms, Introduction to Machine Learning
Problem

You are given v boolean variables x0,x1,...,xv1 that xi can be either 1 (true) or 0 (false).
Let us define an environment env, an assignment of either 0 or 1 to all v variables (like v=3, env={x0=0,x1=1,x2=0}).
Also, let us define an expression exp, a string that can be generated by the following grammar:expression::=x0 | x1 | ... |xv1 | operationoperation::=(not expression)| (expression and expression)| (expression or expression)| (expression xor expression)

For example, is an expression.
Each expression has a value in an environment. (for example, expression ((x0 xor x1) or x2) has value 0 in environment {x0=1,x1=1,x2=0} but it has value 1 in environment {x0=0,x1=0,x2=1} ).

You are given n environments env1,env2,...,envn and their expected value y1,y2,...,yn (the value that the expressions should have in them), find an expression that satisfies environments as much as possible, and uses operations (and, or, not, xor) as least as possible, in other words for each of 20 tests your score will be:

  • Let exp be your expression.
  • Let cnt be the number of environments like envi that exp in envi=yi.
  • score=e(cntn)21e1×(1number of used oprations1.5×n×v)×5

Input format

  • The first line contains two integers v and n separated by space.
  • Each of the following n lines contains space-separated envi and yienvi is a string containing 0 and 1s of length v, the jth character in envi is value of vj in envi.

Output format

Print a single line of the expression.

Constraints

  • 1n100
  • In 7 tests: 7v10
  • In 3 tests: 10<v20
  • In other tests: 30v50

Notes

  • The expression should not contain any space.
  • Print i instead of xi.
  • Print following characters instead of operations:
    • & for and.
    • | for or.
    • ! for not.
    • ^ for xor.
  • For example, ((x2 xor (not x1)) or x0) should be printed as ((2!1)|0).
  • You can use at most 1.5×n×v operations.
  • The expression's length can be at most 3×104.
Sample Input
3 2
101 1
011 0
111 1
Sample Output
((0&(!1))|(0&1))
Time Limit: 7
Memory Limit: 256
Source Limit:
Explanation

Also experssion x0 (should be printed 0) satisfies all enviroments.

Editor Image

?