题目链接:http://codeforces.com/problemset/problem/711/C
DP
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=1e2+10;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){if(y==0) return x;return gcd(y,x%y);
}
int n,m,k,v[maxn];
int val[maxn][maxn];
ll dp[maxn][maxn][maxn];
int main(){cin>>n>>m>>k;rep(i,1,n+1) cin>>v[i];rep(i,1,n+1) rep(j,1,m+1) cin>>val[i][j];mst(dp,0xf);if(v[1]==0) rep(i,1,m+1) dp[1][i][1]=val[1][i];else dp[1][v[1]][1]=0;rep(i,2,n+1){if(v[i]){rep(j,1,m+1) rep(p,1,i+1){if(j!=v[i]) dp[i][v[i]][p]=min(dp[i][v[i]][p],dp[i-1][j][p-1]);else dp[i][v[i]][p]=min(dp[i][v[i]][p],dp[i-1][j][p]);}}else{rep(j,1,m+1) rep(p,1,m+1) rep(q,0,i+1){if(j!=p){dp[i][j][q]=min(dp[i][j][q],dp[i-1][p][q-1]+val[i][j]);}else{dp[i][j][q]=min(dp[i][j][q],dp[i-1][j][q]+val[i][j]);}}}}ll ans=dp[0][0][0];rep(i,1,m+1) ans=min(ans,dp[n][i][k]);if(ans==dp[0][0][0]) puts("-1");else cout<<ans<<endl;return 0;
}