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; }
相关文章推荐
- Java学习总结(1)
- 二叉树------树的子结构
- 如何将word2007 其中某一页变为横向排版
- Android开发之使用Eclipse开发工具实现Android平台JNI的开发
- Android中Canvas的常用方法
- LeetCode OJ 54. Spiral Matrix
- 你知道那些关于mate 的事情吗???
- 在内存中运行可执行程序(转)
- 手机号正则表达式 Javascript
- Hibernate:命名SQL查询
- CDH5.X安装配置kerberos认证过程
- caffe中Blob数据结构
- 2015年我国互联网行业概况及现状分析
- 2016年5月26日下午(妙味课堂js基础-1笔记四)
- Python 练习 12
- react native debugger 远程调试redux工具
- C# 常用的工具方法
- 网易、阿里健康
- 【android】:android之四大组件详解
- MyEclipse 安装 Vrapper 插件