Under construction

Still being built. Things may change

Bipartite Barricade

Time limit2.5sMemory limit1024 MB

Summary
Count the vertex subsets of a bipartite graph whose total weight is at least t and that some matching fully covers, with every subset vertex matched.
Level

Hard8 of 10

Topics
Bit manipulation, Dynamic programming, Graph
Solved
No attempts yet

Problem

In a bipartite graph, the vertices can be split into two disjoint sets AA and BB so that every edge connects a vertex in AA with a vertex in BB. A matching MM is a set of edges where no two edges share a vertex. A matching MM barricades a vertex set VV if every vertex in VV is an endpoint of at least one edge in MM.

Each vertex has an integer weight. The weight of a vertex set is the sum of the weights of its vertices.

Given an integer tt, count the vertex sets VV whose weight is at least tt and which are barricaded by at least one matching.

Input

The first line contains natural numbers nn and mm (1≤n,m≤201 \le n, m \le 20), the number of vertices in sets AA and BB. The vertices are denoted a1,…,ana_1, \dots, a_n and b1,…,bmb_1, \dots, b_m.

Each of the next nn lines contains a string of mm characters. The jj-th character of the ii-th line is '1' if there is an edge between aia_i and bjb_j, and '0' otherwise.

The next line contains the weights v1,…,vnv_1, \dots, v_n of a1,…,ana_1, \dots, a_n (1≤vk≤100000001 \le v_k \le 10000000).

The next line contains the weights w1,…,wmw_1, \dots, w_m of b1,…,bmb_1, \dots, b_m (1≤wk≤100000001 \le w_k \le 10000000).

The last line contains the natural number tt (1≤t≤4000000001 \le t \le 400000000).

Output

Print the number of vertex sets with weight at least tt that are barricaded by at least one matching.

Hint

Explanation of the first sample. The set {a1,a2,b2,b3}\{a_1, a_2, b_2, b_3\} is barricaded by the matching {(a1,b2),(a2,b3)}\{(a_1, b_2), (a_2, b_3)\} and has weight 21. The sets {a3,b2,b3}\{a_3, b_2, b_3\} and {a2,a3,b2,b3}\{a_2, a_3, b_2, b_3\} are barricaded by the matching {(a2,b3),(a3,b2)}\{(a_2, b_3), (a_3, b_2)\}, with weights 21 and 23. All other sets either have weight below 21 or are not barricaded by any matching. For example, the set {a2,a3,b1,b3}\{a_2, a_3, b_1, b_3\} has weight 26, but no matching barricades it.

Examples2

  1. Example 1

    Input
    3 3
    010
    111
    010
    1 2 3
    8 5 13
    21
    
    Expected output
    3
    
  2. Example 2

    Input
    3 2
    01
    11
    10
    1 2 3
    4 5
    8
    
    Expected output
    13