  The concept of the hafnian first appeared in the works on quantum field
theory by E. R. Caianiello. However, it also has an important combinatorial
property: the hafnian of the adjacency matrix of an undirected weighted graph
is equal to the total sum of the weights of perfect matchings in this graph. In
general, the use of the hafnian is limited by the complexity of its
computation. In this paper, we present an efficient method for the exact
calculation of the hafnian of two-parameter matrices. In terms of graphs, we
count the total sum of the weights of perfect matchings in graphs whose edge
weights take only two values. This method is based on the formula expressing
the hafnian of a sum of two matrices through the product of the hafnians of
their submatrices. The necessary condition for the application of this method
is the possibility to count the number of k-edge matchings in some graphs. We
consider two special cases in detail using a Toeplitz matrix as the
two-parameter matrix. As an example, we propose a new interpretation of some of
the sequences from the On-Line Encyclopedia of Integer Sequences and then
provide new analytical formulas to count the number of certain linear chord
diagrams.
