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 ...
随机推荐
- [Bzoj3252]攻略(dfs序+线段树)
Description 题目链接 Solution 可以想到,每次肯定是拿最大价值为最优 考虑改变树上一个点的值,只会影响它的子树,也就是dfs序上的一个区间, 于是可以以dfs序建线段树,这样就变成 ...
- urllib使用四--urlencode,urlparse,
urllib.urlencode 把字典数据转换为URL编码 # -*- coding: cp936 -*- import urllib params = {'score':100,'name':'爬 ...
- Java线程和多线程(七)——ThreadLocal
Java中的ThreadLocal是用来创建线程本地变量用的.我们都知道,访问某个对象的所有线程都是能够共享对象的状态的,所以这个对象状态就不是线程安全的.开发者可以通过使用同步来保证线程安全,但是如 ...
- 第四模块:网络编程进阶&数据库开发 练习
练习题 基于queue模块实现线程池 import threading from multiprocessing import Queue class A(threading.Thread): def ...
- pg数据库数据表异常挂起
pg数据库即是PostgreSQL数据库. 前几天在一个Java项目中,出现运行Java程序后,pg数据库的数据表异常挂起.而且是在某台电脑上出现的,重装数据库也没用,其它电脑未能复现,是个很奇怪的现 ...
- PQFitness
<html> <head> <title></title> <style> *{margin:o;padding:0;} #header{ ...
- 关于mac ox node安装报 npm ERR! registry error parsing json
想安装grunt 遇到2个问题 让npm重新设置一下config: npm config set registry http://registry.cnpmjs.org 然后还报 npm ERR! E ...
- 剑指Offer - 九度1390 - 矩形覆盖
剑指Offer - 九度1390 - 矩形覆盖2014-02-05 23:27 题目描述: 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形 ...
- USACO Section2.3 Controlling Companies 解题报告 【icedream61】
concom解题报告------------------------------------------------------------------------------------------ ...
- poj 1035 纯正的字符串水
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22673 Accepted: 8258 De ...