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

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
		"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<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#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 all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		double dp[110][110]={0};
		double in[110][110]={0};
		rep(i,n)rep(j,n)cin>>in[i][j];
		rep(i,110)dp[0][i]=1;
		loop(i,1,m){
			rep(j,n)rep(k,n)dp[i][k]=max(dp[i][k],dp[i-1][j]*in[j][k]);
		}
		double ma=-1;
		rep(i,n)ma=max(ma,dp[m-1][i]);
		printf("%.2f\n",ma);
		
	}
}

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 = (double)((int)(maxNum*100+0.5))/100;
		printf("%.2f\n",ret);
	}

	return 0;
}

C++: //43
#include<iostream>
#include<algorithm>
#include<iomanip>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    double g[100][100]={{}};
    for(int y=0;y<n;y++){
      for(int x=0;x<n;x++){
	cin>>g[y][x];
      }
    }
    double r[101][100]={{}};
    fill(r[0],r[1],1);
    for(int i=0;i<m-1;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  r[i+1][j]=max(r[i+1][j],r[i][k]*g[k][j]);
	}
      }
    }
    cout<<fixed<<setprecision(2)<<*max_element(r[n-1],r[n])<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n, m;
    double h[105][105], dp[105][105] = {0}, ans;
    rep(i,105){
        dp[0][i] = 1.0;
    }
    while(cin >> n >> m, n||m){
        rep(i,105){
            rep(j,105){
                dp[i][j] = 0;
            }
            dp[0][i] = 1.0;
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                cin >> h[i][j];
            }
        }
        for(int i = 1; i <= m; i++){
            for(int j = 1; j <= n; j++){
                for(int k = 1; k <= n; k++){
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] * h[k][j]);
                }
            }
        }
        printf("%.2f\n", dp[n][m]);
    }

    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;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,m;
  int i,j;
  double dp[105][105];
  double grow[105][105];
  int maxi[105];//??????????????§???????????¨????????´????????\???

  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;

    rep(i,n)rep(j,n)
      cin>>grow[i][j];

    double temp;
    int tempi;
    rep(j,n){
      temp=0;
      rep(i,n)
        if(temp<grow[i][j]){
	  temp=grow[i][j];
	  tempi=i;
	}
      maxi[j]=tempi;
    }
    /*
    rep(i,n)
      cout<<"M"<<maxi[i]<<endl;//?¢????
    */
    rep(j,n)
      dp[0][j]=1.0;

    for(i=1;i<n;i++)
      for(j=0;j<n;j++)
	dp[i][j]=dp[i-1][maxi[j]]*grow[maxi[j]][j];

    double sum=0;

    rep(j,n)
      sum=max(sum,dp[n-1][j]);

    //sum+=0.005;
    printf("%.2f\n",sum);

  }

}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

double g[101][101];
double dp[101][101];

int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0)  break;
		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){
			for(int j=0; j<n; ++j){
				cin >> g[i][j];
			}
		}
		for(int i=0; i<n; ++i){
			dp[1][i]=1;
		}
		for(int i=2; i<=m; ++i){
			for(int j=0; j<n; ++j){
				double tmp=dp[i][j];
				for(int k=0; k<n; ++k){
					tmp=max(tmp,dp[i-1][k]*g[k][j]);
				}
				dp[i][j]=tmp;
			}
		}
		double ans=0;
		for(int i=0; i<n; ++i){
			ans=max(ans,dp[m][i]);
		}
		//ans=((int)(ans*100+0.5))/100;
		ans=int(ans*100+0.5);
		ans/=100;
		printf("%.2f\n",ans);
	}
	return 0;
}