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

package main

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

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()
}

C++: #include <iostream>
#include <cstdio>

const double inf = 1000;

int n, m;
double g[101][101];
double dp[101][101]; //iテ・ツ崢榲ァツ崢ョテ」ツ?ォテ・ツ可催・ツ崢枳テ」ツつ津、ツクツ偲」ツ?暗」ツ?淌ヲツ卍づ」ツ?ョテヲツ慊?・ツ、ツァテ・ツ?、

int main(){
	while(true){
		for(int i = 0; i < 101; ++i){
			for(int j = 0; j < 101; ++j)dp[i][j] = -1;
		}
		
		std::cin >> n >> m;
		if(n == 0 && m == 0)break;
		
		
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				std::cin >> g[i][j];
			}
		}
		
		for(int i = 0; i < n; ++i)dp[0][i] = 1.0;
		
		for(int i = 0; i < m - 1; ++i){
			for(int j = 0; j < n; ++j){
				if(dp[i][j] == -1)continue;
				
				double maxV = -inf;
				int maxI;
				for(int k = 0; k < n; ++k){
					if(maxV < g[j][k])maxV = g[j][k], maxI = k;
				}
				
				dp[i + 1][maxI] = maxV * dp[i][j];
			}
		}
		
		
		double ans = 0;
		for(int i = 0; i < n; ++i){
			if(dp[m - 1][i] > ans)ans = dp[m - 1][i];
		}
		
		printf("%.2f\n", ans);
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

double tbl[102][102];	// ツ行ツづ個値ツづ債前ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ,ツ療アツづ個値ツづ債債。ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ

int main()
{
	int n, m;

	while (cin >> n >> m && n && m ){
		memset (tbl, 0.0, sizeof (tbl ) );
		rep (i, n ){
			rep (j, n ){
				cin >> tbl[i][j];
			} // end rep
		} // end rep
		double res = 0.0;
		rep (i, n ){	// ツ催渉可づ可選ツづ板氾ャツ猟ソ
			double curr = 1.0;
			int pre = i, next = -1;
			for (int j = 1; j < m; j++ ){
				double t = curr;
				rep (k, n ){
					if (t < tbl[pre][k]*curr ){
						t = tbl[pre][k]*curr;
						next = k;
					} // end if
				} // end rep
				pre = next;
				curr = t;
			} // end rep
			res = max (res, curr );
		} // end rep
		printf ("%.02lf\n", res );
	} // end while

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		long double data[101][101];
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				scanf("%lf", &data[i][j]);
			}
		}
		long double dp[101][101];
		for(int i = 0; i < m; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				dp[i][j] = 0;
			}
		}
		for(int i = 0; i < n; ++i)
		{
			dp[0][i] = 1;
		}
		for(int i = 1; i < m; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				for(int k = 0; k < n; ++k)
				{
					dp[i][j] = max(dp[i][j], dp[i - 1][k] * data[k][j]);
				}
			}
		}
		long double maximum = 0;
		for(int i = 0; i < n; ++i)
		{
			maximum = max(maximum, dp[m - 1][i]);
		}
		printf("%.2lf\n", maximum);
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    double fer[101][101];
    double dp[101][101] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	cin >>fer[i][j];
      }
    }
    for(int i=0; i<n; i++){dp[0][i] = 1;}
    for(int i=0; i<m-1; i++){
      for(int j=0; j<n; j++){
	for(int k=0; k<n; k++){
	  dp[i+1][k] = max(dp[i+1][k],dp[i][j]*fer[j][k]);
	}
      }
    }
    double ans = 0;
    for(int i=0; i<n; i++){ans = max(ans,dp[m-1][i]);}
    printf("%.2lf\n",ans);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>

const int MAX_NM = 100;

int N, M;
double table[MAX_NM][MAX_NM];
double dp[MAX_NM][MAX_NM];

int main(){

    while(true){
        std::cin >> N >> M;
    
        if(N == 0 && M == 0)
            break;

        for(int i = 0; i < N; ++i){
            for(int j = 0; j < N; ++j)
                std::cin >> table[i][j];
        }

        for(int i = 0; i < M; ++i){
            for(int j = 0; j < N; ++j){
                if(i == 0){
                    dp[i][j] = 1;
                }
                else{
                    double max = 0;
                    for(int k = 0; k < N; ++k){
                        max = std::max((double)max, table[k][j] * dp[i - 1][k]);
                    }

                    dp[i][j] = max;
                }
            }
        }
        
        double ans = 0;

        for(int i = 0; i < N; ++i)
            ans = std::max(dp[M - 1][i], (double)ans);
        
        printf("%.2f\n", ans);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;

double memo [101][102];
double mp[101][101];
double ans;
int n,m;
int cnt;

void saiki(double seki,double pseki,int mae,int kai) {
  //  cout <<"seki="<<seki<<" mae="<<mae<<" kai="<<kai<<endl;
  cnt++;
  
  if(kai == m && ans < seki) ans = seki;
  if(kai == m && mae != -1) memo[kai][mae] = 1;
  
  if(kai < m) {
    for(int i=1;i<=n;i++) {
      if(memo[kai+1][i] == -1) {
	saiki(seki*mp[mae][i],seki,i,kai+1);
	if(memo[kai][mae] < memo[kai+1][i]*mp[mae][i]) memo[kai][mae] = memo[kai+1][i]*mp[mae][i];
      }
      else {
	if(memo[kai][mae] < memo[kai+1][i]*mp[mae][i])memo[kai][mae] = memo[kai+1][i]*mp[mae][i];
	saiki(memo[kai][mae]*seki,-1,-1,m);
      }
    }
  }
}

int main(){
  
  while(1){
    cin >> n>> m;
    if(n == 0 && m == 0) break;
    
    for(int i=0;i<=n;i++)
      for(int j=0;j<=n;j++)
	if(i == 0 || j == 0) mp[i][j] = 1;
	else cin >> mp[i][j];

    
    for(int i=0;i<=m;i++)
      for(int j=0;j<=n;j++)
	memo[i][j] = -1;

    ans = 0;
    
    int ans2=0;
    for(int i=1;i<=n;i++) {
      saiki(1,1,i,1);
      for(int j=0;j<=n;j++){
	if(ans2 < memo[1][i]) ans2 = memo[1][i];
	memo[1][i] = memo[2][i]= -1;
      }
    } 
    

    
    //    cout << ans2 << endl;
    printf("%.2f\n",ans);
    //cout << cnt << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>

const int MAX_NM = 100;

int N, M;
double table[MAX_NM][MAX_NM];
double dp[MAX_NM][MAX_NM];

int main(){

    while(true){
        std::cin >> N >> M;
    
        if(N == 0 && M == 0)
            break;

        for(int i = 0; i < N; ++i){
            for(int j = 0; j < N; ++j)
                std::cin >> table[i][j];
        }

        for(int i = 0; i < M; ++i){
            for(int j = 0; j < N; ++j){
                if(i == 0){
                    dp[i][j] = 1;
                }
                else{
                    double max = 0;
                    for(int k = 0; k < N; ++k){
                        max = std::max((double)max, table[k][j] * dp[i - 1][k]);
                    }

                    dp[i][j] = max;
                }
            }
        }
        
        double ans = 0;

        for(int i = 0; i < N; ++i)
            ans = std::max(dp[M - 1][i], (double)ans);
        
        std::cout << ans << std::endl;

    }
    return 0;
}