there row m house small city house paint n color label 1 n house paint summer paint againa neighborhood maximal group continuous house paint colorFor example house 12233211 contain 5 neighborhood 1 22 33 2 11given array house m x n matrix cost integer target wherehousesi color house 0 house paint yetcostij cost paint house color j 1return minimum cost painting remain house way exactly target neighborhood if possible return 1 example 1input house 00000 cost 11010110111051 m 5 n 2 target 3output 9explanation Paint house way 12211this array contain target 3 neighborhood 1 22 11cost paint house 1 1 1 1 5 9example 2input house 02120 cost 11010110111051 m 5 n 2 target 3output 11explanation some house paint Paint house way 22122this array contain target 3 neighborhood 22 1 22 cost paint house 10 1 11example 3input house 3123 cost 111111111111 m 4 n 3 target 3output 1explanation Houses paint total 4 neighborhood 3123 different target 3 Constraintsm houseslength costlengthn costilength1 m 1001 n 201 target m0 housesi n1 costij 104