UVA 104 Arbitrage
动态规划类似FLOYD dp[i][j][k] 表示第i个点经过K次到达j点能获得的最大利润
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
#define MAXN 25
double G[MAXN][MAXN];
double dp[MAXN][MAXN][MAXN];
int fa[MAXN][MAXN][MAXN];
int N;
int cnt,ans;
void init()
{
memset(dp,,sizeof(dp));
memset(fa,,sizeof(fa));
for (int i = ; i <= N; i++)
{
dp[i][i][] = 1.0;
for (int j = ; j <= N; j++)
{
fa[i][j][] = i;
if (i == j) continue;
scanf("%lf",&dp[i][j][]);
}
}
}
bool judge()
{
for (int k = ; k <= N; k++)
for (int i = ; i <= N; i++)
if (dp[i][i][k] > 1.01)
{
ans = i;
cnt = k;
//8 printf("%d %d\n",ans,cnt);
return true;
}
return false;
}
void output(int x,int y,int cnt)
{
if (cnt == ) {printf("%d",x);return ;}
//printf("%d %d %d %d\n",x,y,cnt,fa[x][y][cnt]);
output(x,fa[x][y][cnt],cnt - );
printf(" %d",y);
}
int main()//节点i通过K次转换到达节点j能拿到的钱
{
// freopen("sample.txt","r",stdin);
while (scanf("%d",&N) != EOF)
{
init();
for (int k = ; k <= N; k++)
for (int i = ; i <= N; i++)
for (int j = ; j <= N; j++)
for (int p = ; p <= N; p++)
{
if (dp[i][j][k] < dp[i][p][k - ] * dp[p][j][])
{
dp[i][j][k] = dp[i][p][k - ] * dp[p][j][];
fa[i][j][k] = p;//在i经过K次转换到P的过程中第K 是p->j
}
}
bool found = judge();
if (!found) puts("no arbitrage sequence exists");
else { output(ans,ans,cnt); putchar('\n');}
}
return ;
}
UVA 104 Arbitrage的更多相关文章
- uva 104 Arbitrage (DP + floyd)
uva 104 Arbitrage Description Download as PDF Background The use of computers in the finance industr ...
- UVa 104 - Arbitrage(Floyd动态规划)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVA 436 - Arbitrage (II)(floyd)
UVA 436 - Arbitrage (II) 题目链接 题意:给定一些国家货币的汇率.问是否能通过不断换货币使钱得到增长 思路:floyd,完事后推断一下有没有连到自己能大于1的情况 代码: #i ...
- uva 104 Bandwidth
题意: 给一个图, 将其节点以任一序列排列. 1)计算每个节点距离相邻节点的最大距离 dis[i] 2)计算出当前序列中, 所有节点的dis[i], 并求出最大的dis[i] : max_dis 求最 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- UVA题解一
UVA 100 题目描述:经典3n+1问题在\(n \leq 10^6\)已经证明是可行的,现在记\(f[n]\)为从\(n\)开始需要多少步才能到\(1\),给出\(L, R\),问\(f[L], ...
- 紫书 习题 10-4 UVa 1644(素数筛)
素数筛没什么好说的 #include<cstdio> #include<vector> #include<cstring> #define REP(i, a, b) ...
- UVA 12950 : Even Obsession(最短路Dijkstra)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA - 12001 UVa Panel Discussion
Description UVa Panel Discussion The UVa online judge team is arranging a panel discussion for the ...
随机推荐
- POJ:1703-Find them, Catch them(并查集好题)(种类并查集)
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 49867 Accepted: 153 ...
- linux环境下kettle部署(JDK安装配置,kettle安装配置,资源库配置,定时执行job)
一.部署准备 1.1 java安装(略) 1.2 JDK配置 1. 命令行键入“cd /etc”进入etc目录 2. 命令行键入“vi profile”打开profile文件 3. ...
- java练习题——数组
上述代码可以顺利通过编译,并且输出一个“很奇怪”的结果:[Ljava.lang.Object;@2a139a55 为什么会出现这种情况? 直接输出object的对象,系统会输出地址,如果想要输出其中的 ...
- Android开发——弹性滑动的两种实现方式
0. 前言 欢迎转载,转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52538723 我们在Android开发--View滑动的三 ...
- echo shell commands as they are executed
http://stackoverflow.com/questions/2853803/in-a-shell-script-echo-shell-commands-as-they-are-execute ...
- C# Json 序列化大全--任我行
public class JsonHelper { /// <summary> /// 将Model转换为Json字符串 /// </summary> /// <type ...
- Python全栈(一)编程语言介绍
一.编程语言介绍 程序是计算机能读懂的语言,是人和计算机沟通的方式. 计算机无法理解符号,只能理解0,1的二进制. 计算机内的运行状态就像灯泡的开关一样来表示各庄状态,两个灯泡能表示4种状态,无数的灯 ...
- 深入理解net core中的依赖注入、Singleton、Scoped、Transient(四)【转】
原文链接:https://www.cnblogs.com/gdsblog/p/8465401.html 相关文章: 深入理解net core中的依赖注入.Singleton.Scoped.Transi ...
- java中newInstance和new(转)
在Java开发特别是数据库开发中,经常会用到Class.forName( )这个方法.通过查询Java Documentation我们会发现使用Class.forName( )静态方法的目的是为了动态 ...
- 软工实践 - 第十七次作业 Alpha 冲刺 (8/10)
队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/articles/10023469.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长 ...