uva104 - Arbitrage 最小转移步数

uva1451 - Average 单调队列维护下凸曲线 A DNA sequence consists of four letters, A, C, G, and T. The GC-ratio of a DNA sequence is the number of Cs and Gs of the sequence divided by the length of the sequence. GC-ratio is important in gene 阅读详情

Arbitrage 

Background

The use of computers in the finance industry has been marked with controversy lately as programmed trading -- designed to take advantage of extremely small fluctuations in prices -- has been outlawed at many Wall Street firms. The ethics of computer programming is a fledgling field with many thorny issues.

The Problem

Arbitrage is the trading of one currency for another with the hopes of taking advantage of small differences in conversion rates among several currencies in order to achieve a profit. For example, if $1.00 in U.S. currency buys 0.7 British pounds currency, £1 in British currency buys 9.5 French francs, and 1 French franc buys 0.16 in U.S. dollars, then an arbitrage trader can start with $1.00 and earn tex2html_wrap_inline29 dollars thus earning a profit of 6.4 percent.

You will write a program that determines whether a sequence of currency exchanges can yield a profit as described above.

To result in successful arbitrage, a sequence of exchanges must begin and end with the same currency, but any starting currency may be considered.

The Input

The input file consists of one or more conversion tables. You must solve the arbitrage problem for each of the tables in the input file.

Each table is preceded by an integer n on a line by itself giving the dimensions of the table. The maximum dimension is 20; the minimum dimension is 2.

The table then follows in row major order but with the diagonal elements of the table missing (these are assumed to have value 1.0). Thus the first row of the table represents the conversion rates between country 1 and n-1 other countries, i.e., the amount of currency of country i ( tex2html_wrap_inline37 ) that can be purchased with one unit of the currency of country 1.

Thus each table consists of n+1 lines in the input file: 1 line containing n and n lines representing the conversion table.

The Output

For each table in the input file you must determine whether a sequence of exchanges exists that results in a profit of more than 1 percent (0.01). If a sequence exists you must print the sequence of exchanges that results in a profit. If there is more than one sequence that results in a profit of more than 1 percent you must print a sequence of minimal length, i.e., one of the sequences that uses the fewest exchanges of currencies to yield a profit.

Because the IRS (United States Internal Revenue Service) notices lengthy transaction sequences, all profiting sequences must consist of n or fewer transactions where n is the dimension of the table giving conversion rates. The sequence 1 2 1 represents two conversions.

If a profiting sequence exists you must print the sequence of exchanges that results in a profit. The sequence is printed as a sequence of integers with the integer i representing the tex2html_wrap_inline51 line of the conversion table (country i). The first integer in the sequence is the country from which the profiting sequence starts. This integer also ends the sequence.

If no profiting sequence of n or fewer transactions exists, then the line

no arbitrage sequence exists
should be printed.

Sample Input

3
1.2 .89
.88 5.1
1.1 0.15
4
3.1    0.0023    0.35
0.21   0.00353   8.13 
200    180.559   10.339
2.11   0.089     0.06111
2
2.0
0.45

Sample Output

1 2 1
1 2 4 1
no arbitrage sequence exists

  给出货币的汇率,问一种货币换成别的最后再换回来能增长0.01%的最少转移步数是多少。

  这个就像概率论里那个马尔可夫链(从i到j转移k步的所有状态也是从i到m转移n步,再从m到j转移k-n步的所有状态),类似floyd,只不过多了个步数。设f[i][j][step]为i到j走step步增长最多的情况,状态转移方程是f[i][j][step]=min(f[i][k][step-1]*f[k][j][1])。一旦找到满足条件的就直接打印。要打印路径,用path[i][j][step]代表从i到j走step步最后一步的起点(path[i][j][1]=i),递归打印。


#include<cstring>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#define INF 0x3f3f3f3f
#define MAXN 25
#define pii pair<int,int>
using namespace std;
int N;
double f[MAXN][MAXN][MAXN];
int path[MAXN][MAXN][MAXN];

void print_path(int i,int j,int step){
    if(step<=0) return;
    print_path(i,path[i][j][step],step-1);
    printf("%d ",path[i][j][step]);
}
void DP(){
    int i,j,k,step;
    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(f[i][j][step]<f[i][k][step-1]*f[k][j][1]){
                    f[i][j][step]=f[i][k][step-1]*f[k][j][1];
                    path[i][j][step]=k;
                }
        for(i=1;i<=N;i++) if(f[i][i][step]>1.01){
            print_path(i,i,step);
            printf("%d\n",i);
            return;
        }
    }
    printf("no arbitrage sequence exists\n");
    return;
}
int main(){
    freopen("in.txt","r",stdin);
    while(scanf("%d",&N)!=EOF){
        memset(f,0,sizeof(f));
        int i,j;
        for(i=1;i<=N;i++)
            for(j=1;j<=N;j++){
                if(i!=j){
                    scanf("%lf",&f[i][j][1]);
                    path[i][j][1]=i;
                }
            }
        DP();
    }
    return 0;
}


uva10237 - Bishops 互不攻击的象 Problem B Bishops Input: standard input Output: standard output Time Limit: 4 seconds Memory Limit: 32 MB   A bishop is a piece used in thegame of chess which is played on a board of squa 阅读详情

相关推荐

【论文翻译】VIT:An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale

VIT摘要介绍相关工作模型VISION TRANSFORMER (VIT)微调和高分辨率实验结论 摘要 虽然Transformer架构在自然语言处理任务中已经成为事实标准,但是它在计算机视觉领域的应用仍然受限。在视觉领域,注意力要么和卷积网络结合使用,要么替换卷积网络中的某些部分,同时保持整体结构不变。本文表明对CNNs的依赖不是必要的,纯转换器(pure transformer)直接应用于图像块(image patches)序列在图像分类任务中能发挥很好的作用。当对大量数据进行预训练并把它转移到多个中型或

栗子菜菜 1848

UVA - 104 Arbitrage floyd的最初形式

题目大意:有N个国家,每个国家之间都有着汇率,将1.0的货币经过国家间的汇率的转换,最后再变回原来的货币,要求变回来后货币的值要增加,求最少的变换步数 解题思路:这题是要求一个环,值大于1.01的最小环,设置一个状态量dp[i][j][step]为从第i个国家开始,经过step的次数后,到第j个国家的汇率,那么dp[i][j][step] = max(dp[i][j][step],dp[i][k

静静地码 758

AirSim中图像API的应用

解析Airsim图像获取保存的api

fegxg的博客 1610

UVA 104 - Arbitrage

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34268843的博客 170

基于51单片机的通讯聊天系统

通过编写51单片机通讯聊天程序,掌握51单片机的各个模块的知识点和运用C语言编写51单片机的能力。用51单片机与口袋开发板设计实现一个单片机与电脑串口助手实现通讯功能的程序。程序的主要功能如下: 1 OLED初始化显示Welcome to Bluetooth communication! 字符串。 2 程序开始时处于接收信息模式, 电脑串口助手发送信息时,将从初始化字符第一个开始显示,电脑串口助手发送信息后,蜂鸣器响铃2秒左右。 3 每次同时按下左右键时,可以轮流切换接收/发送信息模式 4 在发送信息模式时

m0_47419053的博客 3642

10.18华为OD机试真题 新系统 - 社区赢手机比赛 (Java/Py/C/C++/Js/Go)

10.18华为OD机试真题 新系统 - 社区赢手机比赛 (Java/Py/C/C++/Js/Go)

算法大师! 199

UVA 104 - Arbitrage(floyd变形)

Arbitrage  Background The use of computers in the finance industry has been marked with controversy lately as programmed trading -- designed to take advantage of extremely small fluctu

Remilia's 1461

部署OpenClaw时设置环境变量提示export: not valid in this context的完整解决方案

OpenClaw环境变量设置错误解决方案 问题概述 在部署OpenClaw时设置环境变量出现"export: not valid in this context"错误,通常由以下原因导致: 在非交互式shell中使用export命令 在命令替换或管道中使用export 脚本文件包含Windows换行符(CRLF) 解决方案 修正脚本执行方式:确保export命令在正确的shell上下文中使用 使用source命令:通过. setup_openclaw.sh或source setup_op

博客 461

UVA 104 Arbitrage DP(类似floyd)

Background The use of computers in the finance industry has been marked with controversy lately as programmed trading -- designed to take advantage of extremely small fluctuations in prices -- has be

便纵有千种风情 776

【GlobalMapper精品教程】027:路径剖面和和视线工具的使用

路径剖面视线工具允许您使用加载的高程数据集沿用户指定的路径获取垂直剖面。要定义生成3D路径剖面所遵循的路径,只需单击鼠标左键选择路径的点,然后石键单击以结束路径。出现一个带有剖面的对话框,允许您设置视线分析或优化端点。

智慧空间实验室 2058

uniapp [全端兼容] - 最新详细实现拍摄视频录像并可播放预览视频,调起本机摄像头开启录像录制完毕后保存到本机临时存放,可对拍摄的视频进行压缩处理减少文件大小不损失画质,详解录制视频并读取播放!

uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,录视频,拍视频,拍摄录制视频后上传服务器,调起摄像头录视频并可预览,录视频上传,录像,uniapp录制视频并上传,录制视频并保存到本地设备,如何本地保存并播放预览,提供给用户观看MP4视频录像并上传到后端服务器完整功能源码,视频压缩,mp4文件,删除视频,录像后怎么预览,临时视频文件怎么减少压缩大小,视频压缩及上传,自己录视频并生成可播放的文件,录视频并能打开查看,视频压缩后上传,本机相册,录完怎么预

🏆 前端领域优质创作者 1万+

uva104

#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int n; double dp[25][25][25];//dp[i][j][p]记录i到j且遍历的国家数为p的乘积 int path[25][25][25];//path[i][j][p]记录i到j的第p个遍历的国家 void print

qq_38140099的博客 282

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

uva104(好)

设ratei,j,k)表示i经过k部变换,到j的最大金额,我们有递推公式rate(i,j,k) >?= rate(i,j,k-1)*rate(i,j,1),然后让k从2开始直到n,判断Matrix(i,i,k)是否符合条件。这个问题解决了,还有一个问题就是打印路径,设一个path(i,j,k)如果用flord来实现,则其表示第k-1步所交换的某种汇率,若用经典动归来解,则表示i交换到j,k个交换

龙崎的专栏 713

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

104 Arbitrage

简单问题就是从一个国家到另一个国家能套汇超过1.01即可 选用的算法是Floyd-Warshall,稍作修改,状态转移公式是从一个国家i到另一国家j经过次数k能套汇超过1.01 #include &lt;iostream&gt; #include &lt;vector&gt; using namespace std; class Arbitrage { public: void rea...

彳亍 268

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

uva 104(dp)

题意: 题解: #include #include const int N = 25; int n; double m[N][N]; double f[N][N][N]; int path[N][N][N]; void print(int t, int i, int j) { if (t == 1) { printf("%d", i); return; } print(t

俯瞰风景 969

Uva 104 Abitrage

#include #include #include #include #include #include #include #include #include #include using namespace std; double percent[30][30][30]; int path[30][30][30]; int n; void Print_path(int i,int j,in

zju2016的博客 418

UVa 104-Arbitrage

题意:有N种货币,他们之间能以一定的比率交换,问能不能通过交换赚钱。最多交换N次,

A Cube Master 598

求区间这种数的个数,这个数恰好等于k个互不相等的2的整数次幂之和 数位统计

Description 给定一个区间[x,y],求这个区间中满足下列条件的整数的个数:这个数恰好等于k个互不相等的2的整数次幂之和。例如x=15,y=20,k=2.则有且仅有下列三个数满足题意: 17=2^4+2^0; 18=2^4+2^1; 20=2^4+2^2;   (a^b代表是a的b次方) Input 接下来输入T行,每行对应一个样例,每行有3个整数x, y

1612

数位DP的记忆化搜索形式

数位DP的记忆化搜索形式比一般递推形式好写多了,而且一般不容易出错。   dfs求[0,n]有多少个符合的,先把n换成字符串形式。   cur:现在处理到哪一位。   s:搜索到目前为止,之前的状态,具体什么状态看情况而定。   e:是否到达边界,如果没到这一位只取到9,否则只能取到bit[cur]。   z:前导0标记,也就是是否前面的都是0,有些情况需要特殊判断。   一般情况

1386

uva11481 - Arrange the Numbers N个数前M个错排

Consider this sequence {1, 2, 3, … , N}, as a initial sequence of firstN natural numbers. You can rearrange this sequence in many ways. Therewill be N! different arrangements. You have to calculate t

1160

字符串DP

这几天在做DP,总结一下,先是字符串这一类的。   最简单的就是给你两个字符串a和b,让你求最长公共子序列(LCS)。用dp[i][j]作为第一个字符串匹配到i位置和第二个字符串匹配到j位置时的最长公共子序列,所以如果a[i]==b[j],dp[i][j]=dp[i-1][j-1]+1,否则dp[i][j]=max(dp[i-1][j],dp[i][j-1])。   之后一些题就和是这个的变形

1124

hdu5396 Expression 记忆化搜索+组合数 多校联合第九场

Expression Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 160    Accepted Submission(s): 90 Problem Description Teacher Mai has n nu

1085

uva12105 - Bigger is Better 大数

Bob has n matches. He wants to compose numbers using the following scheme (that is, digit 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 needs 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 matches): Fig 1 Digits from matches Write

1075
上一篇: 差分约束系统
下一篇: 网络流 最大流 Edmonds-Karp算法
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址