#P2761. 软件补丁问题

    ID: 1781 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>O2优化状态压缩,状压网络流 24 题

软件补丁问题

Description

Company T discovered that there are nn bugs in one of its software products and then released mm patch programs for it.

Each patch has its specific applicable environment: a patch can be used only when the software contains certain bugs and at the same time does not contain some other bugs. While removing some bugs, a patch may also introduce new bugs.

In other words, for any patch ii, there are four associated sets B1i,B2i,F1iB1_i,B2_i,F1_i and F2iF2_i. Patch ii can be applied only if the software contains all bugs in B1iB1_i and contains none of the bugs in B2iB2_i. Patch ii will fix the set of bugs F1iF1_i, and at the same time introduce the set of bugs F2iF2_i. In addition, running each patch takes a certain amount of time.

Design an algorithm to use the mm patch programs provided by Company T to repair the original software into a bug-free state, while minimizing the total time. For the given nn bugs and mm patches, find a repair plan with the minimum total time.

Input Format

The first line contains two positive integers nn and mm. Here, nn is the total number of bugs, and mm is the total number of patches.

The next mm lines describe the mm patches. Each line contains a positive integer representing the time required to run patch ii, followed by two strings of length nn, separated by a space character.

In the first string, if the kk-th character is +, then the kk-th bug belongs to B1iB1_i. If it is -, then the kk-th bug belongs to B2iB2_i. If it is 0, then the kk-th bug belongs to neither B1iB1_i nor B2iB2_i, i.e., whether the software contains the kk-th bug does not affect the applicability of patch ii.

In the second string, if the kk-th character is -, then the kk-th bug belongs to F1iF1_i. If it is +, then the kk-th bug belongs to F2iF2_i. If it is 0, then the kk-th bug belongs to neither F1iF1_i nor F2iF2_i, i.e., whether the software contains the kk-th bug will not change after applying patch ii.

Output Format

Output the minimum total time after the program finishes. If there is no solution, output 0.

3 3
1 000 00-
1 00- 0-+
2 0-- -++

8

Hint

Constraints: For 100%100\% of the testdata: 1n201 \le n \le 20, 1m1001 \le m \le 100.

Translated by ChatGPT 5