Arbitrage solution to a problem

START


emmmm, practices and several other solution to a problem should be about, but I think you can explain a little more.

So ado.


This question requires relatively simple, but requires time and finally converted into the original currency profit that is greater than 0.01 (1%), but not more than n times the number of conversions (as possible), then the minimum number of output paths.

note! ! ! ! ! : Title does not require the maximum profit is only required profit is greater than 0.01. The path and there is no specific requirements, but does not exceed n times the minimum, the same path length in a case where any are possible.

Well! We grabbed a more important point - the number of conversions.

In other words, every time conversion, we will convert it into the original currency, to determine whether a profit of 0.01, if reached, then the output of the entire program after it is over. (If there is more money than 0.01, the output of one can)

So, we start in the outer layer of a for loop, loop conversions, not exceed n. (If more than n outputs "no arbitrage sequence exists" a mess).

and! ! ! We need to keep currency of each conversion, the last duck to be output! ! !

Well! Probably frame appears, we need to write core liao, yes, this question is the core of Floyd algorithm spicy.

We used Floyd is generally open a two-dimensional array, but in fact it is three-dimensional compression from, so this question we use three-dimensional array ans [i] [j] [k], i represents the i currencies, j denotes currencies j, k denotes the k th conversion, the conversion from the i represents the overall currency into profit when the j-th k-th currency conversion. (May be a bit around 8)

Further with NXT [i] [j] [k] denotes the i-th converted from money to the currency at the time of the j-th k-th currency conversion.

Well! Conversion type came out liao (though do not know why)! ans [i] [l] [k] = max (ans [i] [l] [k], ans [i] [j] [k-1] * ans [j] [l] [1])

It means to say after the previous conversion, and now want to convert from i to j, trying to k, see if I can make a greater value, then it can become large (larger is not necessarily a disadvantage, because the subject did not ask currency change how much to just ask to be greater than 0.01, so if the current increases, then it can certainly become larger, may be a bit greedy mean ???)

DETAILED ijkl is valid program proceeds kankan 8


Code:

. 1 #include <bits / STDC ++ H.>
 2  #define MAXN 5001
 . 3  the using  namespace STD;
 . 4 __int128 n-, R & lt, G, T, B, Ans; // lazy hit high precision HHHH 
. 5 __int128 ANS [MAXN] [MAXN ]; // dimensional ANS [i] [j] denotes the front i to j th column has a column interference, there is the ij-th column of radiation, laser tower Ni 
. 6  int Read ();
 . 7  void Print (__ int128 X) {
 . 8      IF (X> . 9 ) Print (X / 10 );
 . 9      the putchar (X% 10 + ' 0 ' ); // int128 is not directly output der, so the output to the sub-sub 
10  }
. 11  int main () {
 12 is      // The freopen ( "antbuster.in", "R & lt", stdin);
 13 is      // The freopen ( "antbuster.out", "W", stdout); 
14      n-= Read (), R & lt = read (), G = read (), B = read (), T = read (); // fast read 
15      for ( int I = . 1 ; I <= n-; I ++ )
 16          ANS [I] [ 0 ] = (I- . 1 ) T + * G * ANS [I- . 1 ] [ 0 ]; // initialize, if all the n points placed radially column 
. 17      for ( int I = . 1 ; I <= n; I ++ )
 18          for ( int= J . 1 ; J <I; J ++ )
 . 19              ANS [I] [J] = max (ANS [I- . 1 ] [J- . 1 ] + (ij of) * G * (T + (J- . 1 ) * B), ANS [I- . 1 ] [j] + (IJ- . 1 ) * G * (T + j * B));
 20 is          // common points i, j interfering place where the column 
21 is      for ( int i = 0 ; I <= n-; I ++ )
 22 is          for ( int J = 0 ; J <= I; J ++ )
 23 is              Ans = max (ANS [I] [J] + R & lt * (Ni) * (T + J * B) + ( ij of) * G * (ni) * (J * T + B), Ans);
 24          // over n points, I tower has been placed, placing all of the remaining ni laser tower tower 
25     Print (Ans); // output 
26 is      return  0 ;
 27  }
 28  int Read () // Fast Read 
29  {
 30      int X = 0 , K = . 1 ; char CH = '  ' ;
 31 is      the while (! isdigit (CH)) {
 32          CH = getchar ();
 33 is          IF (CH == ' - ' ) = K - . 1 ;
 34 is      }
 35      the while (isdigit (CH)) {
 36          X = X *10+ch-'0';
37         ch=getchar();
38     }
39     return k*x;
40 }

END

 

Guess you like

Origin www.cnblogs.com/Yz-jw/p/11480666.html