Find a special connected block
All submissions for this problem are available.
Given an n*m board with a number between -1 and n*m in every entries.
And an n*m matrix M is also given, where Mi,j is the cost of selecting the (i,j) entry of the given board.
Your task is to find a connected block (which means these entries can reach each other by just go up, down, left and right without going out the block) in the board that contains at least K distinct positive numbers without any -1, and it must have minimum total cost for selecting these entries. Output the minimum total cost.
First line consists of three integers, n, m, K (1 <= n, m <= 15, 1 <= K <= 7).
The followings are two n*m matrices, the first denotes the numbers on the board and the second denotes the cost of every entry.
Namely, the first n lines contain m integers, where the jth number in ith line denotes the number on the entry (i,j) of the board. These integers are in [-1, n*m].
Next n lines contain m integers too. The jth number in ith line denotes the cost of selecting the entry (i,j) of the board. These integers are in [1, 100000].
Only one line contains the minimum cost to finish the task. If the task is impossible, output -1 please.
Input: 3 3 3 0 0 1 2 3 3 -1 2 1 3 1 5 4 10 1 9 3 4 Output: 8
|Tags||april12, hard, shangjingbo|
|Time Limit:||0.788732 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.5, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.