#include #include #include using namespace std;
#define pow2(x) (1«(x))
const int maxn = 103; const int maxm = 19; const int maxs = pow2(16) + 3;
int n, m, e, d[maxn], c[maxn][maxm], f[maxs], g[maxs];
inline void upMin(int& a, const int& b) { if (a > b) a = b; }
int main() { #ifdef LAEKOV_LOCAL freopen(".in", “r”, stdin); #endif
scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++ i) { scanf("%d", d + i); for (int j = 0; j < m; ++ j) scanf("%d", c[i] + j); } memset(f, 0x3f, sizeof(f)); f[0] = 0; e = pow2(m); for (int i = 1; i <= n; ++ i) { memset(g, 0x3f, sizeof(int) * e); for (int j = 0; j < m; ++ j) for (int k = e - 1; k >= 0; -- k) if (k & pow2(j)) { upMin(g[k], g[k ^ pow2(j)] + c[i][j]); upMin(g[k], f[k ^ pow2(j)] + d[i] + c[i][j]); } for (int j = 0; j < e; ++ j) upMin(g[j], f[j]); memcpy(f, g, sizeof(int) * e); } printf("%d\n", f[e - 1]); }