# Ultraviolet A 104-arbitrage

Source: Internet
Author: User

// Start to use the Implicit Graph search, and the results exceed the memory. Remember that the time is not calculated before you do the question, and the memory limit is faulty.

// First, it indicates that this question can use dynamic rules. The difficulty lies in how to output the shortest switching mode. In this light, one dimension is required to mark [STEP].

// Then Floyd + motion gauge, O (n4) is enough

# Include <iostream> <br/> # include <memory. h> <br/> # include <cstdio> <br/> # include <stack> </P> <p> using namespace STD; <br/> const int max = 25; <br/> const Double E = 1e-9, Sta = 1.01; <br/> bool findflag; <br/> int N, sign, totalstep; <br/> double map [Max] [Max] [Max], way [Max] [Max]; <br/> stack <int> S; <br/> inline int dbcmp (const double & X) {<br/> If (x>-E & x <E) <br/> return 0; <br/> return x> 0? 1:-1; <br/>}< br/> int main () <br/>{< br/> freopen ("I .txt", "r", stdin ); <br/> int K; <br/> while (CIN> N) {<br/> memset (way, 0, sizeof (way )); <br/> memset (MAP, 0, sizeof (MAP); <br/> for (INT I = 1; I <= N; I ++) {<br/> for (Int J = 1; j <= N; j ++) {<br/> if (I = J) {<br/> map [I] [J] [1] = 1.0; <br/> way [I] [J] [1] = I; <br/> continue; <br/>}< br/> CIN> map [I] [J] [1]; <br/> way [I] [J] [1] = I; <br/>}< br/> findflag = 0; <br/> For (INT step = 2; Step <= N; Step ++) {<br/> for (k = 1; k <= N; k ++) {<br/> for (INT I = 1; I <= N; I ++) {<br/> for (Int J = 1; j <= N; j ++) {<br/> If (Map [I] [J] [STEP] <map [I] [k] [step-1] * map [k] [J] [1 ]) {<br/> map [I] [J] [STEP] = map [I] [k] [step-1] * map [k] [J] [1]; <br/> way [I] [J] [STEP] = K; <br/>}< br/> if (I = J) <br/> If (dbcmp (Map [I] [J] [STEP]-Sta) = 1) {<br/> findflag = 1; <br/> Sign = J; <br/> totalstep = step; <br/> goto ans; <br/>}< br/>} <Br/>}< br/> ans: <br/> If (findflag) {<br/> while (! S. empty () s. pop (); <br/> int end = sign; <br/> S. push (sign); <br/> for (INT I = totalstep; I> = 2; end = way [sign] [end] [I], I --) <br/> S. push (way [sign] [end] [I]); <br/> cout <way [sign] [end] [1]; <br/> while (! S. empty () {<br/> cout <"" <S. top (); <br/> S. pop (); <br/>}< br/> cout <Endl; <br/>}< br/> else <br/> cout <"no arbitrage sequence exists" <Endl; <br/>/* For (INT I = 1; I <= N; I ++) {<br/> for (Int J = 1; j <= N; j ++) {<br/> cout <map [I] [J] <""; <br/>}< br/> cout <Endl; <br/>}*/<br/>}< br/> return 0; <br/>}</P> <p>

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.