zoukankan      html  css  js  c++  java
  • Coin game (coin)

    Description


    Before the game starts, (n) coins are placed on a ring clockwise, and the (i) coin has a face value of (w_i).
    At each step of the game, you need to select one of the coins, place it in the position of the next coin in the clockwise direction, and remove the coin that has been covered. Your score in this step is the absolute value of the difference between the face values of the two coins. After that, you need to continue the operation until there is only one coin left. Your final score is the sum of the scores of each step.
    Please write a program to find the best strategy to maximize the final score.

    Format


    Input

    The first line contains a positive integer (n), which represents the number of coins.
    The second line contains (n) positive integers (w_1), (w_2), ..., (w_n), which represent the face value of each coin in clockwise order.

    Output

    Output an integer per line, which is the maximum value of the final score.

    Sample


    Input

    4
    3 4 5 6
    

    Output

    6
    

    Hint


    For the data of (100\%), (1 le w_i le 10^6).

    Test point number (n)
    (1,2,3) (leq 5)
    (4,5,6) (leq 20)
    (7,8,9,10) (leq 300)

    Sample Code


    Code is not available!
    
  • 相关阅读:
    C++ 日期 & 时间
    C++ 引用
    C++ 指针
    C++ 字符串
    C++ 数组
    C++ 数字
    C++ 函数
    C++ 判断
    C++ 循环
    C++ 运算符
  • 原文地址:https://www.cnblogs.com/jiupinzhimaguan/p/13817620.html
Copyright © 2011-2022 走看看