Noip simulation exercises 8

Noip simulation exercises 8

  • All black purple question title.
  • First only put questions surface,Gugu Gu

Rabbit farming

Description

  • Farmer income in recent years, and much of recession, when he was worried about how to earn more money, he heard the children next door to the issues discussed in the rabbit breeding.

    The problem is this: the first beginning with a pair of newborn rabbits, after two months of growing up, which is the rabbit from the first three months, a pair of small monthly newborn rabbit. Newborn bunnies after two months of growth but also give birth to a pair of small rabbits per month. Q. How many n-month rabbits?

    Smart you may have noticed, the number of rabbits n months is just the n-th Fibonacci (Fibonacci) number. After another, do not know what is the number of Fibonacci, but he also discovered the law: the i + the number of rabbits for 2 months is equal to the number of i-rabbit month plus the number of rabbits i + 1-month period. The number of rabbits in previous months were:

    1 1 2 3 5 8 13 21 34 …

    And much more to find faster growth in the number of rabbits behind and look forward to raising rabbits will be able to make big money, so after another in the first month bought a pair of bunnies start breeding.

    Every day, after another, to be fed to rabbits, rabbits eat very special time, every k always rabbits in a circle, what is left of the circle k inadequate, especially due to the fear of loneliness rabbit, from three months, only one surrounded by a circle of a pair of rabbits if eating, this rabbit will soon die.

    We always assume that newborn rabbit died, then the number of rabbits per month can still be calculated. For example, when k = 7, the number of months before the rabbits as follows:

    1 1 2 3 5 7 12 19 31 49 80 …

    Given n, and much help you can calculate the n-th month how many rabbits he had it? Since the answer may be quite large, you just need to tell and much of the n-th month of the number of rabbits in addition to the remainder of p.

Input

  • Input line, comprising three positive integer n, k, p.

Output

  • Output one line containing an integer that represents the n th month after another rabbit on the number of a remainder p.

Sample Input

6 7 100

Sample output

7

Data Size

  • 1<=n<=10^18

    2<=k<=10^6

    2<=p<=10^9

Einsatzgruppen

Description

  • You have a team of n reservist soldiers of the army, soldiers numbered from 1 to n, we want them to be split into a number of special operations team transferred to the battlefield. For tacit consideration, with a special operations team members numbering should be continuous, that is shaped like a (i, i + 1, ... , i + k) sequence.
      I number of soldiers fighting for the initial xi, initial combat a particular sports team x is the initial squad of soldiers and combat effectiveness, namely x = (xi) + (xi + 1) + ... + (xi + k).
      Through long-term observation, you summed up a special operations team of the initial combat x will be amended to the following empirical formula x ': x' = ax ^ 2 + bx + c, where a, b, c are known coefficients ( a <0).
      As a troop commander, and now you want to battle for the armed forces, so that the sum of the maximum combat effectiveness of all the special operations teams correction. Try and find the maximum.
      For example, you have four soldiers, x1 = 2, x2 = 2 , x3 = 3, x4 = 4. Empirical formula parameters a = -1, b = 10, c = -20. In this case, the best solution is to soldiers three special operations teams: the first team includes soldiers 1 and 2 soldiers, 3 second team includes soldiers, a third team includes 4 soldiers. The initial fighting special operations teams were 4,3,4, fighting revised respectively 4,1,4. Revised combat and 9, no other program can combat and larger as amended.

Input

  • Input consists of three lines. The first row contains an integer n, the total number of soldiers. The second line contains three integers a, the coefficient b, c, of the empirical formula. The third line contains n integers separated by spaces x1, x2, ..., xn, respectively numbered 1, 2, ..., n of the initial combat soldiers.

Output

  • Output An integer representing the maximum value of all special operations teams and combat effectiveness of the amendment.

Sample Input

4 
-1 10 -20 
2 2 3 4 

Sample output

9

patrol

topic:

  • There are pictures. Turn link

Guess you like

Origin www.cnblogs.com/BigYellowDog/p/11620476.html