Codeforces 358D Dima and Hares
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的更多相关文章
- Codeforces 358D Dima and Hares:dp【只考虑相邻元素】
		题目链接:http://codeforces.com/problemset/problem/358/D 题意: 有n个物品A[i]摆成一排,你要按照某一个顺序将它们全部取走. 其中,取走A[i]的收益 ... 
- Codeforces Round #208 (Div. 2) 358D Dima and Hares
		题目链接:http://codeforces.com/problemset/problem/358/D 开始题意理解错,整个就跪了= = 题目大意:从1到n的位置取数,取数的得到值与周围的数有没有取过 ... 
- [CodeForce]358D Dima and Hares
		有N<3000只宠物要喂,每次只能喂一只,每喂一只宠物,宠物的满足度取决于: 1 紧靠的两个邻居都没喂,a[i] 2 邻居中有一个喂过了,b[i] 3 两个邻居都喂过了,c[i] 把所有宠物喂一 ... 
- 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 ... 
- CF358D Dima and Hares
		CF358D Dima and Hares 洛谷评测传送门 题目描述 Dima liked the present he got from Inna very much. He liked the p ... 
- CodeForces 584D   Dima and Lisa
		1e9 以内的判断一个数是否是素数,可以直接朴素的暴力. 这倒题除了考虑1e9以内的素数的判断,还有一个歌德巴赫猜想:任意一个奇数都可一分解为三个素数的和. 第三个结论:素数是密集的,1e9以内, ... 
- Codeforces Little Dima and Equation 数学题解
		B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ... 
- codeforces  B. Dima and Text Messages  解题报告
		题目链接:http://codeforces.com/problemset/problem/358/B 题目意思:给出n个单词(假设为word1,word2.word3...wordn)和一句test ... 
- codeforces  A. Dima and Continuous Line  解题报告
		题目链接:http://codeforces.com/problemset/problem/358/A 题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个 ... 
随机推荐
- IC卡接口芯片TDA8007的读写器设计
			摘要:阐述T=0传输协议,给出IC卡读写器中使用的IC卡APDU指令流程和原理框图:重点介绍其中的IC卡接口芯片Philips的TDA8007,给出通过TDA8007对CPU IC卡上下电过程.具体程 ... 
- Python 在Visual studio  中做单元测试进行TDD开发
			Unit Tests Steve Dower edited this page on 14 Jul · 3 revisions Pages 38 Home Azure Remote Debugging ... 
- 【Xamarin For  IOS 开发需要的安装文件】
			官网安装文件下载: http://download.xamarin.com/XamarinforMac/Mac/xamarin.mac-2.0.1.64.pkghttp://download.xama ... 
- 如何使用git创建项目,创建分支
			git config -global user.name "Your name" git config -global user.email "you@example.c ... 
- 关于group by
			<pre name="code" class="sql">关于group by 排序问题 10g 以前sort group by 需要排序 10g ... 
- 【转】Android 定时器实现的几种方式和removeCallbacks失效问题详解--不错
			原文网址:http://blog.csdn.net/xiaanming/article/details/9011193 实现定时器有很多种方式,在这里我简单的介绍几种方式 (1)使用Handler + ... 
- 在Visual Studio 2013中编译libssh2项目
			 一. 下载需要的外部包,并解压,下面给出的链接如果无法访问,就google搜索下载一下: •下载openssl •下载zlib 二.修改libssh2项目配置: 1.C/C++->Gene ... 
- asp.net 中的错误跳转 customerrors 对html文件不起作用
			在配置web.config时发现customerrors对aspx文件是起作用的,我想通过customerrors来判断是否有html文件时,却不起作用? 这是为什么,如果要起作用.net里该如何操作 ... 
- pip 错误Requested **, but installing version **
			使用pip升级时,虽然指定了版本,也使用了--upgrade参数,但pip就是不升级,Requested **, but installing version **,手动删了源文件也不行.后来发现一个 ... 
- phpcms:二、头部尾部包含
			1.index.html是默认的首页{template "content","header"}引入头部的模块{template "content&qu ... 
