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:2385-Apple Catching(dp经典题)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14311 Accepted: 7000 Descr ...
- 15.2,redis发布订阅
发布publish 订阅subscribe Redis 通过 PUBLISH . SUBSCRIBE 等命令实现了订阅与发布模式. 举例1: qq群的公告,单个发布者,多个收听者 发布/订阅 实验 发 ...
- Android开发——View滑动的三种实现方式
0. 前言 Android开发中,我们常常需要View滑动实现一些绚丽的效果来优化用户体验.一般View的滑动可以用三种方式实现. 转载请注明出处:http://blog.csdn.net/seu ...
- Android的Fragment介绍
前言 fragment是从android3.0开始提出来的,用来支持大屏幕设备的ui设计.通过将activity划分为多个fragment,不仅提高了设计的灵活性,而且可以在程序运行时改变它们的特征, ...
- 缓存(CDN缓存,浏览器(客户端)缓存)
1.什么是缓存? 缓存是一种数据结构,用于快速查找以及执行的操作结果.因此,如果一个操作执行起来很慢,对于常用的输入数据就可以将操作的结果缓存,并在下次调用该操作时使用缓存的数据. 缓存是一个到处都存 ...
- runtime怎么添加属性、方法等
ivar表示成员变量 class_addIvar class_addMethod class_addProperty class_addProtocol class_replaceProperty
- Pythontutor:可视化代码在内存的执行过程
http://www.pythontutor.com/visualize.html今天去问开发一个Python浅拷贝的问题,开发给了一个神器,可以可视化代码在内存的执行过程,一看即懂,太NB了!~真是 ...
- ASP.NET Core [4]: Authentication(笔记)
原文连接:http://www.cnblogs.com/RainingNight/p/authentication-in-asp-net-core.html 在现代应用程序中,认证已不再是简单的将用户 ...
- Spring Boot多数据源配置(二)MongoDB
在Spring Boot多数据源配置(一)durid.mysql.jpa 整合中已经讲过了Spring Boot如何配置mysql多数据源.本篇文章讲一下Spring Boot如何配置mongoDB多 ...
- 孤荷凌寒自学python第五天初识python的列表
孤荷凌寒自学python第五天 列表 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 粗俗地区分列表,可以这样理解,定义或print列表后显示时,列表中的各元素都是用一个方括号[]括起来的. ...