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>
#include <cmath>
#include <algorithm>

int n, m;
double grow[100][100];
double dp[110][110];

int main() {
    while(std::cin >> n >> m, n + m) {
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            std::cin >> grow[i][j];
        }
    }

    for(int i = 0; i < n; ++i) {
        dp[0][i] = 1.;
    }
    for(int i = 1; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            dp[i][j] = 0.;
        }
    }

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

    printf("%.2f\n", *std::max_element(dp[m - 1], dp[m - 1] + n));


    }
}

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 i=0;i<n;i++) res = max(res,dp[m-1][i]);

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

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<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(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]);
    //cout<<sum<<endl;
    sum+=0.004999;
    printf("%.2f\n",sum);
    //printf("%f\n",sum);

  }

}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


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

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
const int MAX_N =120;
const int MAX_M =120;
double dp[MAX_N][MAX_M];//dp[i][j]:=直前にjを与え、i回目に肥料を与えたときの最大の成長
double memo[MAX_N][MAX_N];
int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}
		int a =max(n,m);
		for(int i =0;i <=a;i++){
			for(int j =0;j <=a;j++){
				dp[i][j] =0;
				memo[i][j]=0;
			}
		}
		rep(i,n){
			rep(j,n){
				cin>>memo[i][j];
			}
		}
		rep(i,n)dp[1][i] =1.00;

		double ans =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][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
				}
			}
		}
		rep(i,n)ans=max(ans,dp[m][i]);
		ans =ans*100;
		ans =round(ans)/100;
		printf("%.2lf\n",ans);
	}
	return 0;
}

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

const double inf = 1000;

int n, m;
double g[101][101];
double dp[101][101]; //i???????????????j,??????k???????????????????????§???

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){
				for(int k = 0; k < n; ++k){
					dp[i + 1][k] = std::max(dp[i + 1][k], dp[i][j] * g[j][k]);
				}
			}
		}
		
		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;
}