Go: // n×nの成長度表に現れる数字を重複を許してm-1個選んで掛け合わせる時の最大値を求める
// ->掛け算型のDP

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		m, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		growth_table := make([][]float64, n)
		for i := range growth_table {
			scanner.Scan()
			buf_ := strings.Split(scanner.Text(), " ")
			tmp := make([]float64, n)
			for j := range tmp {
				tmp[j], _ = strconv.ParseFloat(buf_[j], 64)
			}
			growth_table[i] = tmp
		}
		dp := make([][]float64, m)
		for i := range dp {
			dp[i] = make([]float64, n)
		}
		for i := range dp {
			dp[0][i] = 1
		}
		for k := 1; k < m; k++ {
			// k個使うとき...
			for i := 0; i < n; i++ {
				for j := 0; j < n; j++ {
					// 新たにgrowth_table[i][jを使うかどうか
					dp[k][j] = max(dp[k][j], dp[k-1][i]*growth_table[i][j])
					// check(dp)
				}
			}
		}
		ans := 0.0
		for i := 0; i < n; i++ {
			if dp[m-1][i] > ans {
				ans = dp[m-1][i]
			}
		}
		fmt.Printf("%.2f\n", ans)
	}
}

func max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

// func check(dp [][]float64) {
// 	log.Println()
// 	for i := range dp {
// 		log.Println(dp[i])
// 	}
// 	log.Println()
// }

Python: while True:
  n, m = map(int, input().split())
  if n == 0:
    break
  gs = [list(map(float, input().split())) for _ in range(n)]
  dp = [[0] * n for _ in range(m + 1)]
  for i in range(n):
    dp[1][i] = 1.0
  for i in range(2, m + 1):
    for j in range(n):
      dp[i][j] = max([dp[i - 1][k] * gs[k][j] for k in range(n)])
  print(format(max(dp[m]), ".2f"))

Python: while 1:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    g=[map(float,raw_input().split()) for _ in xrange(n)]
    dp=[[0.0]*n for _ in xrange(m)]
    for j in xrange(n):
        dp[0][j]=1.0
    for i in xrange(m-1):
        for j in xrange(n):
            for k in xrange(n):
                dp[i+1][j]=max(dp[i+1][j],dp[i][k]*g[k][j])
    print("%.2f" % round(max(dp[m-1]),2))

Python: while 1:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    g=[map(float,raw_input().split()) for _ in xrange(n)]
    dp=[[0.0]*n for _ in xrange(m+1)]
    for j in xrange(n):
        dp[0][j]=1.0
    for i in xrange(m):
        for j in xrange(n):
            for k in xrange(n):
                dp[i+1][j]=max(dp[i+1][j],dp[i][k]*g[k][j])
    print(max(dp[m-1]))

Python: # AOJ 0191: Baby Tree
# Python3 2018.6.20 bal4u

while True:
	n, m = list(map(int, input().split()))
	if n == 0: break
	d =  [[0.0 for j in range(n)] for i in range(n)]
	for i in range(n): d[i] = list(map(float, input().split()))
	dp =  [[0.0 for j in range(n)] for k in range(m)]
	for i in range(n): dp[0][i] = 1
	for k in range(1, m):
		for i in range(n):
			for j in range(n):
				dp[k][j] = max(dp[k][j], dp[k-1][i]*d[i][j])
	ans = 0
	for i in range(n):
		if dp[m-1][i] > ans: ans = dp[m-1][i]
	print(format(ans, ".2f"))

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
#MOD = 1000000007
MOD = 10000
EPS = 0.000000001
sys.setrecursionlimit(100000)


while True:

    N,M = map(int,input().split())
    if N == 0 and M == 0:
        break

    table = [list(map(float,input().split())) for _ in range(N)]

    dp = [[0]*N for _ in range(M)]
    for i in range(N):
        dp[0][i] = 1.0

    for i in range(1,M): #回数のループ
        for k in range(N):
            for p in range(N):
                dp[i][p] = max(dp[i][p],dp[i-1][k]*table[k][p])

    ans = 0.0
    for i in range(N):
        ans = max(ans,dp[M-1][i])

    print("%.2f"%(ans))

Python: from math import sqrt
prime = [1 for _ in xrange(10**6+1)]
prime[1] = 1
prime[0] = 0
for i in xrange(2, int(sqrt(10**6+1))+1):
    if prime[i] == 1:
        for j in xrange(i+i, 10**6+1, i):
            prime[j] = 0
while True:
    N, X = map(int, raw_input().split())
    if (N, X) == (0, 0): break
    price = [input() for _ in xrange(N)]
    dp = [0] * (X+1)
    dp[0] = 1
    for i in xrange(X+1):
        if dp[i] == 0: continue
        for p in price:
            if i + p <= X:
                dp[i+p] = 1
    for i in xrange(X, -1, -1):
        if i > 0 and dp[i] == 1 and prime[i] == 1:
            print(i)
            break
    else:
        print("NA")

Python: while 1:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    g=[map(float,raw_input().split()) for _ in xrange(n)]
    dp=[[0.0]*n for _ in xrange(m+1)]
    for j in xrange(n):
        dp[0][j]=1.0
    for i in xrange(m):
        for j in xrange(n):
            for k in xrange(n):
                dp[i+1][j]=max(dp[i+1][j],dp[i][k]*g[k][j])
    print(round(max(dp[m-1]),2))

Python: import random
def my_round(f):
  x, y = str(f).split(".")
  if len(y) <= 2:
    return x + "." + y + "0" * (2 - len(y))
  if y[2] >= "5":
    z = float(x + "." + y[:2]) + 0.01
  else:
    z = float(x + "." + y[:2])
  l, r = str(z).split(".")
  if len(r) <= 2:
    return l + "." + r + "0" * (2 - len(r))
  else:
    return l + "." + r[:2]
"""
def test(f):
  print(f, my_round(f))

for _ in range(1000):
  r = random.random()
  test(r)
"""
while True:
  n, m = map(int, input().split())
  if n == 0:
    break
  gs = [list(map(float, input().split())) for _ in range(n)]
  dp = [[0] * n for _ in range(m + 1)]
  for i in range(n):
    dp[1][i] = 1.0
  for i in range(2, m + 1):
    for j in range(n):
      dp[i][j] = max([dp[i - 1][k] * gs[k][j] for k in range(n)])
  print(my_round(max(dp[m])))

Python: #coding:utf-8
from __future__ import division,print_function
try:
    input = raw_input
    range = xrange
except NameError:
    pass
# 上記のコードはPython2とPython3の違いを一部吸収するためのもの

# http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=916014

# N * Mの表をつくる.すべての要素はvにする。
def make_matrix(N,M,v):
    # return [[v for i in range(M)] for j in range(N)]とも書ける。
    ret = []
    for i in range(N):
        l = []
        for j in range(M):
            l.append(v)
        ret.append(l)
    return ret


# gは行列(二次元配列)
def solve(n,m,g):
    # current_max[i][j] = 直前がjの場合のi日目の最大成長度
    # 負の数にはなりえない。
    current_max = make_matrix(m,n,-1)
    # 最初は何をあげても1.0のまま
    for i in range(n):
        current_max[0][i] = 1.0
    for i in range(1,m):
        # jは次にあげるもの
        for j in range(n):
            # 前に何をあげてたか
            # current_max[i][j] = max(current_max[i-1][k] * g[k][j]) for k in [0,n]
            for k in range(n):
                current_max[i][j] = max(current_max[i][j],
                                        current_max[i-1][k]*g[k][j])
    ret = max(current_max[m-1])
    ret = round(ret,3)
    print("%.2f" % ret)

def main():
    while True:
        # 受けとった文字列をintに変換する(リストの内包表記)
        n,m = [int(i) for i in input().split(" ")]
        if n == 0 and m == 0:
            return
        g = []
        for i in range(n):
            g.append([float(x) for x in input().split(" ")])

        solve(n,m,g)
main()

Python: def my_round(f):
  x, y = str(f).split(".")
  if len(y) <= 2:
    return x + "." + y + "0" * (2 - len(y))
  if y[2] >= "5":
    z = float(x + "." + y[:2]) + 0.01
  else:
    z = float(x + "." + y[:2])
  l, r = str(z).split(".")
  return l + "." + r + "0" * (2 - len(r))

while True:
  n, m = map(int, input().split())
  if n == 0:
    break
  gs = [list(map(float, input().split())) for _ in range(n)]
  dp = [[0] * n for _ in range(m + 1)]
  for i in range(n):
    dp[1][i] = 1.0
  for i in range(2, m + 1):
    for j in range(n):
      dp[i][j] = max([dp[i - 1][k] * gs[k][j] for k in range(n)])
  print(my_round(max(dp[m])))