CF358D.Dima and Hares

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.

Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?

Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.

Help Inna maximize the total joy the hares radiate. :)

季马非常喜欢因娜送给他的礼物。而他对谢尔盖送给他的礼物则更加喜爱。

季马对因娜送的礼物感激不已,于是决定买 nn 只野兔送给因娜。因娜非常开心,她将这些野兔排成一排,从左到右依次编号为 11 到 nn,并开始用胡萝卜喂养它们。因娜决心每只野兔恰好喂一次。但她该按什么顺序来喂呢?

因娜注意到:每当她喂某只野兔时,这只野兔便会散发出喜悦。而某只野兔所散发的喜悦值,取决于在喂它之前,它的相邻野兔是否已被喂过。因娜知道:对于每只野兔,若它在喂食时其左右相邻野兔都尚未被喂(即“都还饿着”)、或恰好有一只相邻野兔已被喂(即“一只饱了”)、或两只相邻野兔都已被喂(即“都饱了”),其所散发的喜悦值分别是多少。请注意:编号为 11 和 nn 的野兔分别没有左邻和右邻野兔,因此它们永远不可能有两个已被喂过的相邻野兔。

请帮助因娜安排喂食顺序,使得所有野兔散发的喜悦值之和最大。 :)

输入格式

The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers _a_1 _a_2 ... a__n. The second line contains _b_1, _b_2, ..., b__n. The third line contains _c_1, _c_2, ..., c__n. The following limits are fulfilled: 0 ≤ a__i, b__i, c__i ≤ 105.

Number a__i in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number b__i in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number с__i in the third line shows the joy that hare number i radiates if both his adjacent hares are full.

输入的第一行包含一个整数 nn(1 ≤ n ≤ 30001 ≤ n ≤ 3000)—— 表示野兔的数量。随后是三行,每行包含 nn 个整数。第一行包含整数 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n;第二行包含 b1, b2, …, bnb_1,\,b_2,\,\dots,\,b_n;第三行包含 c1, c2, …, cnc_1,\,c_2,\,\dots,\,c_n。满足如下限制条件:0 ≤ ai, bi, ci ≤ 1050 ≤ a_i,\,b_i,\,c_i ≤ 10^5。

第一行中的数 aia_i 表示:当第 ii 只野兔的两只相邻野兔均处于饥饿状态时,该野兔所获得的快乐值;
第二行中的数 bib_i 表示:当第 ii 只野兔恰好有一只相邻野兔处于饱食状态时,该野兔所辐射出的快乐值;
第三行中的数 cic_i 表示:当第 ii 只野兔的两只相邻野兔均处于饱食状态时,该野兔所辐射出的快乐值。

输出格式

In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.

在一行中,输出因娜通过喂食野兔所能获得的最大总快乐值。

输入输出样例

  • 输入#1

    4
    1 2 3 4
    4 3 2 1
    0 1 1 0

    输出#1

    13
  • 输入#2

    7
    8 5 7 6 1 8 9
    2 7 9 5 4 3 1
    2 3 3 4 1 1 3

    输出#2

    44
  • 输入#3

    3
    1 1 1
    1 2 1
    1 1 1

    输出#3

    4

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

首页