Minimal price P20023


Statement
 

pdf   zip

You have nn tasks to do, and nn workers that can do them. For each task 1in1 \le i \le n and each worker 1jn1 \le j \le n, p[i][j]p[i][j] is the price that the worker ii does the task jj.

Write a program that computes the minimal price of assigning exactly one different task to each worker.

Input

Input consists of a natural 1n101 \le n \le 10, followed by pp, the matrix n×nn \times n of prices (nn lines with nn natural numbers between 1 and 1000).

Output

Your program must print the minimal price of assigning exactly one different task to each worker.

Observation

There are algorithms of polynomial cost to solve this problem, but are difficult to program. Implement a backtracking.

Public test cases
  • Input

    3
    5 2 1
    2 1 3
    1 3 7
    

    Output

    3
    
  • Input

    4
    2 5 7 9
    2 2 2 2
    2 1 8 3
    2 9 9 8
    

    Output

    12
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python