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 ...
随机推荐
- Hive 中的 UDF
LanguageManual UDF 一.分类 UDF:User defined function 用户定义函数 一进一出 UDAF:User defined aggregation function ...
- 14 Django的用户认证组件
用户认证 auth模块 from django.contrib import auth django.contrib.auth中提供了许多方法,这里主要介绍其中的三个: 1.1 .authentica ...
- ListView getChildCount 以及getChildAt 坑 误区指南
今天调试的时候,才知道. 原来listview 的 getChildCount 取得是当前可先的list item 的个数,而不是整个listview 的count. 整个listview 的数量应该 ...
- setBackgroundResource和setImageResource的区别
setBackgroundResource是设置view的背景图片 setImageResource是设置ImageView的图片 对于一个imagevewButton来说,你既可以setBackgr ...
- Android Studio自定义模板代码
http://blog.csdn.net/h183288132/article/details/51916399 生成模板看上面这个博客就可以了,不再重复制造轮子. 不过需要补充的是: 还应该有下面的 ...
- CC3200串口UART1配置
1. 首先打开工程\CC3200SDK_1.1.0\example\adc\ewarm,以ADC例程为例,修改串口引脚复用,先看下引脚图 2. 修改引脚复用代码 void PinMuxConfig(v ...
- 路由vue-router基础
目录 1. 基本例子 2. 动态路由匹配 3. 嵌套路由 4. 编程式导航 5. 命名路由 6. 命名视图 7. 重定向和别名 8. 向路由组件传递props 9. HTML5 History模式 官 ...
- python-configparser模块,xml.etree模块
操作键值对文件 #文件db格式为 [section] a = 1 b = 2 [section1] d = 3 c = 4 import configparser #获取所有节点 config = c ...
- [译]14-spring 集合元素的注入
前面的文章已经介绍了如何往bean里面注入原始类型和引用类型.我们使用bean元素的contructor-arg或property子 元素的value属性注入java原始类型;同理,我们可以使用bea ...
- java5初学
1.Eclipse快捷键 alt + / 代码提示,例如自动创建main方法ctrl + d 删除当前行ctrl + alt + up/down 复制当前行alt + up/down 交换行ctrl ...