#P2761. 软件补丁问题
软件补丁问题
Description
Company T discovered that there are bugs in one of its software products and then released 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 , there are four associated sets and . Patch can be applied only if the software contains all bugs in and contains none of the bugs in . Patch will fix the set of bugs , and at the same time introduce the set of bugs . In addition, running each patch takes a certain amount of time.
Design an algorithm to use the patch programs provided by Company T to repair the original software into a bug-free state, while minimizing the total time. For the given bugs and patches, find a repair plan with the minimum total time.
Input Format
The first line contains two positive integers and . Here, is the total number of bugs, and is the total number of patches.
The next lines describe the patches. Each line contains a positive integer representing the time required to run patch , followed by two strings of length , separated by a space character.
In the first string, if the -th character is +, then the -th bug belongs to . If it is -, then the -th bug belongs to . If it is 0, then the -th bug belongs to neither nor , i.e., whether the software contains the -th bug does not affect the applicability of patch .
In the second string, if the -th character is -, then the -th bug belongs to . If it is +, then the -th bug belongs to . If it is 0, then the -th bug belongs to neither nor , i.e., whether the software contains the -th bug will not change after applying patch .
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 of the testdata: , .
Translated by ChatGPT 5
京公网安备 11011102002149号