D - Testing Pants for Sadness

本文探讨了一个有趣的算法问题,即在最坏情况下,一名完全不了解考试主题的考生需要进行多少次点击才能通过由多个选择题组成的计算机考试,每个选择题都有特定数量的答案选项。文章提供了一个有效的算法解决方案,用于计算所需的最小点击次数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called “Testing Pants for Sadness”.

The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.

A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.

Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test’s theme. How many clicks will he have to perform in the worst case?

Input
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.

Output
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:

the first click selects the first variant to the first question, this answer turns out to be wrong.
the second click selects the second variant to the first question, it proves correct and we move on to the second question;
the third click selects the first variant to the second question, it is wrong and we go back to question 1;
the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
the fifth click selects the second variant to the second question, it proves correct, the test is finished.
题意:给你n道题,每题有a[i]个选项,选错一个要退回到第一道题重新开始,问你最少需要多少次才能在最坏的情况下做对全部题目。
思路:
最坏情况下也就是说对于每个a[i]个你都要试a[i]次,而且其中a[i]-1次的错误的你都要返回第一题重新开始。

#include"iostream"
using namespace std;
int main()
{
	int n;
	long long a,sum;
	while(cin>>n)
	{
		sum=0;
		for(int i=0;i<n;i++)
		{
			cin>>a;
			sum+=(a+(a-1)*i);
		}
		cout<<sum<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值