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

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
#define SIZE 105
double dp[SIZE][SIZE];
int n,m;
double level[SIZE][SIZE];
int main()
{
	while(1)
	{
		scanf("%d %d",&n,&m);
		if(n==0&&m==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				scanf("%lf",&level[i][j]);
			}
		}
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++)dp[1][i]=1.0;
		for(int i=1;i<m;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]*level[j][k]);
				}
			}
		}
		double ans=0.0;
		for(int i=0;i<n;i++)ans=max(ans,dp[m][i]);
		printf("%.2f\n",ans);
	}
	return 0;
}

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

using namespace std;

int main(){

	double table[101][101];

	int n,m;
	const int INF=100000000;
	while(cin>>n>>m&&!(n==0&&m==0)){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++)
				cin>>table[i][j];
		}
		double dp[2][101];
		fill(dp[0],dp[0]+101,1);
		fill(dp[1],dp[1]+101,0);

		double *prv=dp[0];
		double *nxt=dp[1];
		for(int k = 0; k < m-1; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					nxt[i]=max(nxt[i],prv[j]*table[j][i]);
				}
			}
			swap(prv,nxt);
			fill(nxt,nxt+101,0);
		}

		double maxNum=0;
		for(int i = 0; i < n; i++){
			maxNum=max(maxNum,prv[i]);
		}
		double ret = ((int)(maxNum*100+0.5))/100;
		printf("%.2f\n",ret);
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
double key[100][100];
double table[100][100];

void Init(int n, int m){
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) table[i][j] = 0;
}

double memo(int cur, int count, int limit, int kind){
	if(table[cur][count]) return table[cur][count];
	if(count==limit) return 1.0;
	double Max = 0;
	int prev = 0;
	for(int i = 0; i < kind; i++){
		double tmp = memo(i, count+1, limit, kind);
		if(Max <= tmp){
			if(Max*key[prev][cur] < tmp*key[i][cur]){
				Max = tmp;
				prev = i;
			}
		}
	}
	table[cur][count] = Max*key[prev][cur];
	return table[cur][count];
}

int main(){
	int n, m;
	while(cin >> n >> m && ((n!=0)||(m!=0))){
		Init(n, m);
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> key[i][j];
		for(int i = 0; i < n; i++) table[i][0] = memo(i, 1, m, n);
		double max = 0;
		for(int i = 0; i < n; i++) if(max < table[i][0]) max = table[i][0];
		printf("%0.2f\n", max);
	}

	return 0;
}

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

using namespace std;

int n,m;
double dp[101][100];
double t[100][100];

double solve(int times, int prev){
  if(dp[times][prev] != -1) return dp[times][prev];
  if(times == m) return dp[times][prev]=1;

  double tmp=-1;
  for(int i=0;i<n;i++){
    if(times == 0){
      tmp = max(tmp, solve(times+1, i) * 1);
    }else{
      tmp = max(tmp, solve(times+1, i) * t[prev][i]);
    }
  }
  
  return dp[times][prev] = tmp;
}

int main(void){
  while(cin >> n >> m){
    if(!(n|m)) break;
    fill((double *)dp, (double *)dp+101*101, -1);
    double retd;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> t[i][j];
      }
    }
    retd = solve(0,0) * 100;
    printf("%.2lf\n", round(retd) /  100);
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<vector<double> > d(n,vector<double>(n));
    vector<double> now(n,1),past(n,1);
  
    rep(i,n)rep(j,n)cin>>d[i][j];
    rep(times,m-1){
      rep(i,n){
	rep(j,n){
	  // i is past , j is now
	  now[j] = max(now[j],past[i] * d[i][j]);
	}
      }
      past = now;
    }
    double ret = -1;
    rep(i,now.size())ret=max(ret,now[i]);
    printf("%.2f\n",ret);
  }
  
  
}

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

const int MAX_N = 100, MAX_M = 100;
const double EPS = 1e-10;

int n,m;
double g[MAX_N][MAX_N];
double dp[MAX_M][MAX_N]; //dp[cnt][prev]

double rec(int cnt, int prev)
{

    if(cnt == 0)
        return dp[0][prev] = 1.0;

    if(dp[cnt][prev] > -0.1)
        return dp[cnt][prev];
    
    double tmp, ret = 0.0;
    for(int i = 0; i < n; i++) {
        tmp = rec(cnt - 1, i) * g[prev][i];
        if(ret < tmp) 
            ret = tmp;
    }

    return dp[cnt][prev] = ret;
}

int main()
{
    while(cin >> n >> m && n) {

        for(int i = 0; i < m; i++) 
            for(int j = 0; j < n; j++) 
                scanf("%lf", &g[i][j]);
        
        for(int i = 0; i < m; i++) 
            for(int j = 0; j < n; j++) 
                dp[i][j] = -1.1;

        double ans = 0.0, tmp;
        for(int i = 0; i < n; i++) {
            tmp = rec(m - 1, i);
            if(ans < tmp)
                ans = tmp;
        }

        printf("%.2lf", ans);
    }
}