#include
#include
#define MaxN 21
#define Profit 1.01
int n;
double map[MaxN][MaxN];
double arb[MaxN][MaxN];
int way[MaxN][MaxN][MaxN];
int from,to,len;
double tmp[MaxN][MaxN];
int tmpw[MaxN][MaxN][MaxN];
int main()
{
int i,j,k,h;
while(scanf("%d",&n)!=EOF)
{
for (i=0; i for (j=0; j {
if (i==j) map[i][j]=1; else scanf("%lf",&map[i][j]);
arb[i][j]=map[i][j]; way[i][j][0]=j;
}
from=-1; to=-1; len=-1;
for (j=0; j for (k=0; k if (arb[j][k]*map[k][j]>Profit)
{from=j; to=k; len=0; goto loop;}
for (i=1; i<=n-2; i++)
{memcpy(tmp,arb,sizeof(arb));
memcpy(tmpw,way,sizeof(way));
for (j=0; j for (k=0; k for (j=0; j for (h=0; h for (k=0; k if (tmp[j][k]*map[k][h]>arb[j][h])
{arb[j][h]=tmp[j][k]*map[k][h];
memcpy(way[j][h],tmpw[j][k],sizeof(tmpw[j][k]));
way[j][h][i]=h;
}
for (j=0; j for (k=0; k if (arb[j][k]*map[k][j]>Profit)
{from=j; to=k; len=i;goto loop;}
}
loop:
if (len==-1) printf("no arbitrage sequence exists\n");
else
{printf(" %d",from+1);
for (k=0; k<=len; k++) printf(" %d",way[from][to][k]+1);
printf(" %d\n",from+1);
}
}
}
阅读(533) | 评论(0) | 转发(0) |