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 <algorithm>

using namespace std;

int main()
{
	int n, m;
	long double r, a[101][101], dp[101][101];
	
	while(cin>>n>>m && (m+n)){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> a[i][j];
			}
		}
		fill(&dp[0][0], &dp[100][100], 0);
		
		for(int i = 0; i < n; i++){
			dp[i][0] = 1.0;
		}
		
		for(int k = 1; k < m; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					dp[i][k] = max(dp[i][k], dp[j][k-1]*a[j][i]);
				}
			}
		}
		
		r = 0.0;
		for(int j = 0; j < n; j++){
			r = max(r, dp[j][m-1]);
		}
		
		printf("%.2f\n", r);
	}
	
	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+1; 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++){
		int tmp = memo(i, count+1, limit, kind);
		if(Max == tmp){
			if(Max*key[prev][cur] < tmp*key[i][cur]){
				Max = tmp;
				prev = i;
			}
		}
		if(Max < tmp){
			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<bits/stdc++.h>
using namespace std;

double c[100][100];
double dp[100][100];//i??\??????j???????????¬
signed main() {
	int a, b;
	while(scanf("%d%d", &a, &b),a|b) {
		for (int d = 0; d < a; d++) {
			for (int e = 0; e < a; e++) {
				scanf("%lf", &c[d][e]);
			}
		}
		for (int d = 0; d < b; d++) {
			for (int e = 0; e < a; e++) {
				if (d == 0)dp[d][e] = 1;
				else dp[d][e] = -(1 << 15);
			}
		}
		for (int d = 0; d < a; d++)dp[0][d] = 1;
		for (int d = 1; d < b; d++) {
			for (int e = 0; e < a; e++) {//????????\
				for (int f = 0; f < a; f++) {//????????\
					dp[d][e] = max(dp[d][e], dp[d - 1][f] * c[f][e]);
				}
			}
		}
		double MAX = -(1 << 15);
		for (int d = 0; d < a; d++) {
			MAX = max(MAX, dp[b - 1][d]);
		}
		printf("%.10lf\n", MAX);
	}
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

double dp[101][101];
double table[100][100];

int main(){

	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				scanf("%lf",&table[y][x]);
			}
		}

		fill((double*)dp,(double*)dp+101*101,0.0);
		for(int i=0;i<n;i++) dp[0][i] = 1.0;

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

		double res = -1.0;
		for(int k=0;k<m;k++) for(int i=0;i<n;i++) res = max(res,dp[k][i]);

		printf("%.2lf\n",floor(res+0.005+eps));
	}
}

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

int main(){
	while(1){
		int n,m;
		std::cin>>n>>m;
		if(n+m==0&&n*m==0)break;
		double dp[101][101]={};//dp[i][j]=i????????§???????????\??????j?????¨???????????????????????§???
		double grow[101][101];//i??´????????\??????j???????????\???
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)std::cin>>grow[i][j];
		}
		for(int i=1;i<=n;i++)dp[1][i]=1.0;
		for(int i=2;i<=m;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					dp[i][j]=std::max(dp[i][j],dp[i-1][k]*grow[k][j]);
				}
			}
		}
		double ans=0;
		for(int i=1;i<=n;i++)ans=std::max(ans,dp[m][i]);
		std::cout<<std::fixed<<std::setprecision(2)<<ans<<std::endl;
	}
	return 0;
}

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

int main(){
  int n,m;
  while(cin >> n >> m && (n|m)){
    double a[100][100], dp[2][100];
    for(int i=0;i<n;i++){
      dp[0][i] = 1.0;
      dp[1][i] = -1.0;
      for(int j=0;j<n;j++) cin >> a[i][j];
    }

    for(int i=0;i<m-1;i++){
      for(int j=0;j<n;j++){
        for(int k=0;k<n;k++){
          dp[1][k] = max(dp[1][k], dp[0][j] * a[j][k]);
        }
      }
      for(int j=0;j<n;j++){
        dp[0][j] = dp[1][j];
        dp[1][j] = -1.0;
      }
    }

    double ans = -1.0;
    for(int i=0;i<n;i++) ans = max(ans,dp[0][i]);
    printf("%.2f\n",ans);
  }
}

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;
      }
      for(int j=0;j<=m;j++)for(int k=0;k<=n;k++)memo[j][k] = -1;
    } 
    

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

  return 0;
}