http://codeforces.com/contest/358/problem/D

题意:给出n个数,每个数取走的贡献与相邻的数有关,如果取这个数的时候,左右的数都还没被取,那么权值为a,如果左右两个数有一个被取走了,那么权值为b,如果左右两个数都被取走了,那么权值为c,求取取走全部数的最大值。

思路:f[i][1][0]代表这个位置在i-1选后才选,f[i][1][1]代表这个位置在i+1选后才选,f[i][0][0]代表这个位置在3个中是第一个选的,f[i][2][0]代表这个位置在3个中是最后选的。

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
int n,a[][],f[][][];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
int n=read();
for (int j=;j<=;j++)
for (int i=;i<=n;i++)
a[i][j]=read();
for (int i=;i<=n;i++)
for (int j=;j<=;j++)
for (int k=;k<=;k++)
f[i][j][k]=-0x3f3f3f3f;
f[][][]=a[][];
f[][][]=f[][][]=-0x3f3f3f3f;
f[][][]=a[][];
for (int i=;i<=n;i++){
f[i][][]=std::max(f[i-][][]+a[i][],f[i-][][]+a[i][]);
f[i][][]=std::max(f[i-][][]+a[i][],f[i-][][]+a[i][]);
f[i][][]=std::max(f[i-][][]+a[i][],f[i-][][]+a[i][]);
f[i][][]=std::max(f[i-][][]+a[i][],f[i-][][]+a[i][]);
}
int ans=;
ans=f[n][][];
ans=std::max(ans,f[n][][]);
printf("%d\n",ans);
return ;
}

Codeforces 358D Dima and Hares的更多相关文章

  1. Codeforces 358D Dima and Hares:dp【只考虑相邻元素】

    题目链接:http://codeforces.com/problemset/problem/358/D 题意: 有n个物品A[i]摆成一排,你要按照某一个顺序将它们全部取走. 其中,取走A[i]的收益 ...

  2. Codeforces Round #208 (Div. 2) 358D Dima and Hares

    题目链接:http://codeforces.com/problemset/problem/358/D 开始题意理解错,整个就跪了= = 题目大意:从1到n的位置取数,取数的得到值与周围的数有没有取过 ...

  3. [CodeForce]358D Dima and Hares

    有N<3000只宠物要喂,每次只能喂一只,每喂一只宠物,宠物的满足度取决于: 1 紧靠的两个邻居都没喂,a[i] 2 邻居中有一个喂过了,b[i] 3 两个邻居都喂过了,c[i] 把所有宠物喂一 ...

  4. Codeforces 358 D. Dima and Hares

    dp[i][0]表示i号兔子先于i-1号兔子喂食,dp[i][1]反过来. 倒着DP D. Dima and Hares time limit per test 2 seconds memory li ...

  5. CF358D Dima and Hares

    CF358D Dima and Hares 洛谷评测传送门 题目描述 Dima liked the present he got from Inna very much. He liked the p ...

  6. CodeForces 584D Dima and Lisa

    1e9 以内的判断一个数是否是素数,可以直接朴素的暴力.   这倒题除了考虑1e9以内的素数的判断,还有一个歌德巴赫猜想:任意一个奇数都可一分解为三个素数的和. 第三个结论:素数是密集的,1e9以内, ...

  7. Codeforces Little Dima and Equation 数学题解

    B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. codeforces B. Dima and Text Messages 解题报告

    题目链接:http://codeforces.com/problemset/problem/358/B 题目意思:给出n个单词(假设为word1,word2.word3...wordn)和一句test ...

  9. codeforces A. Dima and Continuous Line 解题报告

    题目链接:http://codeforces.com/problemset/problem/358/A 题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个 ...

随机推荐

  1. cf C. Prime Number

    http://codeforces.com/contest/359/problem/C 先求出分子的公因子,然后根据分子上会除以公因子会长生1,然后记录1的个数就可以. #include <cs ...

  2. poj1704

    题目大意:n个石子,每次可以取一个石子向左移动,左边有边界限制,每个位置最多同时放一个石子,求先手必胜还是必败. 首先,我们将石子两两配对,每一对,若是先手可以将左边的向左移动一格,则可以用后手将右边 ...

  3. windows下重命名一个带有前缀"."dot字符的名字的错误问题

    如果用正常的右键重命名那么肯定会报错的,比如: 有一个名为project的文件,我想把它命名为.project,加了个前缀dot.然后window就报错了,弹出个对话框让“你必须输入一个文件名”.它可 ...

  4. 【转】Ubuntu命令行下安装、卸载、管理软件包的方法

    原文网址:http://oss.org.cn/html/47/n-67447.html 一.Ubuntu中软件安装方法 1.APT方式 (1)普通安装:apt-get install softname ...

  5. requireJS define require

    原文地址:http://blog.csdn.net/xiaogou56a/article/details/21340213 define 用来定义模块 require 用来加载模块 1 因为定义一个模 ...

  6. 修改xcode代码风格设置

    1.找到文件:/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/S ...

  7. Hive 6、Hive DML(Data Manipulation Language)

    DML主要是对Hive 表中的数据进行操作的(增 删 改),但是由于Hadoop的特性,所以单条的修改.删除,其性能会非常的低所以不支持进行级操作: 主要说明一下最常用的批量插入数据较为常用的方法: ...

  8. Entity framework - start

    http://blogs.msdn.com/b/adonet/archive/2010/07/19/absolue-beginners-guide-to-entity-framework.aspx?R ...

  9. 弹出框layer的使用封装

    layer弹出框官方网址:http://layer.layui.com/ layer常用方法的封装:layerTool.jsp layer.config({ extend: 'extend/layer ...

  10. TBB入门

    获取TBB TBB的官方网站在http://threadingbuildingblocks.org/,可以在它的Downloads页面里找到Commercial Aligned Release,最新版 ...