A1142 | [COCI-2007_2008-regional]#3 NIKOLA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Against his own will, Nikola has become the main character in a game. The game is played on a row of N squares, numbered 1 to N. Nikola is initially in square 1 and can jump to other squares. Nikola's first jump must be to square
2. Each subsequent jump must satisfy two constraints:
• If the jump is in the forward direction, it must be one square longer than the preceding jump.
• If the jump is in the backward direction, it must be exactly the same length as the preceding jump.
For example, after the first jump (when on square 2), Nikola can jump back to square 1 or forwards to square
4.
Every time he enters a square, Nikola must pay an entry fee. Nikola's goal is to get from square 1 to square N as cheaply as possible
2. Each subsequent jump must satisfy two constraints:
• If the jump is in the forward direction, it must be one square longer than the preceding jump.
• If the jump is in the backward direction, it must be exactly the same length as the preceding jump.
For example, after the first jump (when on square 2), Nikola can jump back to square 1 or forwards to square
4.
Every time he enters a square, Nikola must pay an entry fee. Nikola's goal is to get from square 1 to square N as cheaply as possible
输入格式
The first line contains the integer N, 2 ≤ N ≤ 1000, the number of squares.
Each of the following N lines contains the entry fee for one square, a positive integer less than 50
0.
The entry fees will be given in order for squares 1 to N.
Each of the following N lines contains the entry fee for one square, a positive integer less than 50
0.
The entry fees will be given in order for squares 1 to N.
输出格式
Output the smallest total cost for Nikola to get to square N.
输入输出样例
输入 #1
6 1 2 3 4 5 6
输出 #1
12
输入 #2
8 2 3 4 3 1 6 1 4
输出 #2
14
In the first example, after jumping to square 2, Nikola jumps back to square 1. From there he can jump
to square 3 and then to 6.
to square 3 and then to 6.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted