CF268B.Buttons

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.

Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.

Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.

马瑙正在尝试打开一个相当具有挑战性的锁。该锁上有 nn 个按钮,要打开它,你必须按照特定的顺序按下这些按钮。当你按下某个按钮时,它要么保持被按下的状态(这意味着你猜对了,按下了序列中下一个正确的按钮),要么所有已按下的按钮都会弹回初始位置。当所有按钮同时被按下时,锁即被打开。

考虑一个包含三个按钮的例子。假设开锁序列为 {2,3,1}\{2, 3, 1\}:

  • 若你首先按下按钮 1 或 3,则所有按钮会立即弹起;
  • 若你首先按下按钮 2,则它保持被按下状态;
  • 若在按下 2 后再按下 1,则所有按钮均弹起;
  • 若在按下 2 后再按下 3,则按钮 2 和 3 均保持被按下状态;
  • 一旦已有两个按钮被按下,你只需再按下按钮 1 即可打开锁。

马瑙并不知道开锁序列。但他非常聪明,并将采取最优策略。请计算在最坏情况下,他需要按动按钮的总次数。

输入格式

A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.

一行包含一个整数 nn(1≤n≤20001 \leq n \leq 2000)—— 表示锁上的按钮数量。

输出格式

In a single line print the number of times Manao has to push a button in the worst-case scenario.

在一行中输出 Manao 在最坏情况下需要按按钮的次数。

输入输出样例

  • 输入#1

    2

    输出#1

    3
  • 输入#2

    3

    输出#2

    7

说明/提示

Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.

考虑第一个测试样例。Manao 可能在第一次按压时失败并按错按钮。在这种情况下,他仅需第二次按压即可猜出正确的按钮。而他的第三次按压将按下第二个正确按钮。因此,在最坏情况下,他仅需 3 次按压。

输入解题思路,AI测评打分。不知道怎么写?

首页