您的位置:首页 > 其它

Uva 104 Abitrage

2016-05-26 16:50 204 查看
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<stack>
using namespace std;

double percent[30][30][30];
int path[30][30][30];
int n;

void Print_path(int i,int j,int step)
{
if(step==0)
{
printf("%d",i);
return;
}
Print_path(i,path[i][j][step],step-1);
printf(" %d",j);
}

void search()
{
int step;
int i,j,k,m;
for(step=2;step<=n;step++)
{
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(percent[i][j][step]<percent[i][k][step-1]*percent[k][j][1])
{
percent[i][j][step]=percent[i][k][step-1]*percent[k][j][1];
path[i][j][step]=k;
}
}
}
}
for(i=1;i<=n;i++)
{
if(percent[i][i][step]>1.01)
{
m=i;
break;
}
}
if(i<=n)
break;
}
if(step>n)
{
printf("no arbitrage sequence exists\n");
return;
}
Print_path(m,m,step);
printf("\n");
}

int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(percent,0,sizeof(percent));
memset(path,0,sizeof(path));
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j)
percent[i][j][1]=1.0;
else
scanf("%lf",&percent[i][j][1]);
path[i][j][1]=j;
}
}
search();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: