您的位置:首页 > 其它

codeforces Buttons 数学公式构建

2014-04-30 13:46 417 查看
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.

Input

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

Output

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

Sample test(s)

input
2


output
3


input
3


output
7


这样的题目虽然不难,但是要构建个数学公式还真不容易的。

做多了,居然有感觉了,可以感知到大概公式是什么样的,然后验证它。

本题公式就是:

S = n + (n-1) + (n-2) * 2 + (n - 3) * 3 ...

至于怎么想出来的?

模拟一下他的操作,然后得出数列,最后从数列中总结出规律,然后写出去公式。

#include <iostream>
using namespace std;

void Buttons()
{
	int n = 0;
	cin>>n;
	int ans = n;
	int c = 1;
	while (--n)
	{
		ans += n * c;
		c++;
	}
	cout<<ans;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: