Buying items
Practice
4.9 (26 votes)
Ad Hoc
Algorithms
Brute Force search
Dijkstra's algorithm
Graphs
Medium
Shortest path algorithm
簡単 普通
Problem
68% Success 5491 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

There are n different types of objects. You want to buy atleast one instance of each type of object. There are m people , each of them sells one set of objects at a certain price (price is for the set).
Each of these m people sells either nothing or all the objects in the set he has. Information of these m sellers is represented by matrix M of size \(m * n \) . if \(M_{i,j} = 1\), it means that \(i^{th}\) seller has one \(j^{th}\) type of object in his set, otherwise \(M_{i,j} = 0\) . The \(i^{th}\) seller will sell set of all his objects at price \(C_i\).
You want to buy at least one object of each type (it is guaranteed that it is always possible to do so). Find the minimal cost needed to pay to achieve it.

\(\textbf{Input}\)

The first line contains two integers \(n, \; m\) separated by space. (\(1 \le n \times m \le 500\)).

The \((i + 1)^{th}\) (\(1 \le i \le m\)) line contains \((n + 1)\) integers - \(M_{i,1}, \; M_{i,2}, \; M_{i,3}, \dots, M_{i,n}, \; C_i\). (\(0 \le M_{i,j} \le 1, 1 \le C_i \le 10^9\)).

\(\textbf{Output}\)

Output the minimal cost you should pay to buy at least one object of each type.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
12 votes
Tags:
AlgorithmsGraphsMediumShortest Path Algorithm
Points:30
24 votes
Tags:
AlgorithmsGraphsMediumShortest Path Algorithm
Points:30
7 votes
Tags:
ApprovedGraphsMathMediumOpenShortest Path Algorithm