yukicoder-45

从 Trac 迁移的文章

这是从旧校内 Wiki 迁移的文章,可能存在一些样式问题,您可以向 memset0 反馈。

原文章内容如下:

{{{
#!html
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});</script>
<script type="text/javascript" async src="http://10.71.10.90/sfiction/tool/MathJax/MathJax-master/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<style>
.input, pre {
    display: block;
    padding: 9.5px;
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.42857143;
    color: #333;
    word-break: break-all;
    word-wrap: break-word;
    background-color: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 4px;
}
</style>
}}}

== [https://yukicoder.me/problems/no/45 No.45 回転寿司] ==

=== Description ===

{{{
#!html
<p>给一个数列 $V_1, V_2, \dots, V_N$,从中选择若干个数,要求被选中的数在数列中两两不相邻。求被选中的数总和的最大值。</p>
}}}

=== Input ===

{{{
#!html
<p class="input">
$N$<br>
$V_1, V_2, \dots, V_N$<br>
</p>
<p>
$1 \le N \le 1000, 1 \le V_i \le 100$。
</p>
}}}

=== Output ===

{{{
#!html
<p>输出被选中的数总和的最大值。</p>
}}}

=== Sample ===

==== Sample 1 ====
输入
{{{
#!html
<pre>
4
1 2 3 4
</pre>
}}}
输出
{{{
#!html
<pre>
6
</pre>
}}}
解释:选 2 和 4。

==== Sample 2 ====
输入
{{{
#!html
<pre>
4
5 4 4 9
</pre>
}}}
输出
{{{
#!html
<pre>
14
</pre>
}}}
解释:选 5 和 9。

==== Sample 3 ====
输入
{{{
#!html
<pre>
7
1 2 9 10 1 1 4
</pre>
}}}
输出
{{{
#!html
<pre>
16
</pre>
}}}
解释:选 2,10 和 4。

==== Sample 4 ====
输入
{{{
#!html
<pre>
1
100
</pre>
}}}
输出
{{{
#!html
<pre>
100
</pre>
}}}

No.45 回転寿司

Description

给一个数列 $V_1, V_2, \dots, V_N$,从中选择若干个数,要求被选中的数在数列中两两不相邻。求被选中的数总和的最大值。

Input

$N$
$V_1, V_2, \dots, V_N$

$1 \le N \le 1000, 1 \le V_i \le 100$。

Output

输出被选中的数总和的最大值。

Sample

Sample 1

输入

41 2 3 4

输出

6

解释:选 2 和 4。

Sample 2

输入

45 4 4 9

输出

14

解释:选 5 和 9。

Sample 3

输入

71 2 9 10 1 1 4

输出

16

解释:选 2,10 和 4。

Sample 4

输入

1100

输出

100