Codeforces Round #208 (Div. 2) 358D Dima and Hares
题目链接:http://codeforces.com/problemset/problem/358/D
开始题意理解错,整个就跪了= =
题目大意:从1到n的位置取数,取数的得到值与周围的数有没有取过有关,所有数都要取,求最终得到的最大结果
解题思路:dp题,转移方程如下
dp[i][0]=max(dp[i-1][0]+b[i-1],dp[i-1][1]+c[i-1])
dp[i][1]=max(dp[i-1][0]+a[i-1],dp[i-1][1]+b[i-1])
a,b,c分别表示周围没有数,有一个数,有两个数取过的情况。
dp[i][0]表示取i个位置时,i-1没取过的情况。(实际取数的情况,先i,再i-1)
dp[i][1]表示取i个位置时,i-1取过的情况。(实际取数的情况,先i-1,再i)
代码如下:
// 2013/10/26
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 3005
int a[N],b[N],c[N];
int dp[N][];
int main()
{
int n,i;
memset(dp,,sizeof(dp));
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&a[i]);
}
for(i=;i<=n;i++)
scanf("%d",&b[i]);
for(i=;i<=n;i++)
scanf("%d",&c[i]);
if(n==)
cout<<a[]<<endl;
else
{
dp[][]=b[];
dp[][]=a[];
// dp[i][0]表示i位置时(i-1)没喂过
// dp[i][1]表示i位置时(i-1)喂过
for(i=;i<=n;i++)
{
dp[i][]=max(dp[i-][]+b[i-],dp[i-][]+c[i-]);
//前者顺序n[i],n[i-1],n[i-2],后者顺序n[i-2],n[i],n[i-1]
dp[i][]=max(dp[i-][]+a[i-],dp[i-][]+b[i-]);
//n[i-1],n[i-2],n[i];n[i-2],n[i-1],n[i]
}
int ans=max(dp[n][]+a[n],dp[n][]+b[n]);
cout<<ans<<endl;
}
return ;
}
Codeforces Round #208 (Div. 2) 358D Dima and Hares的更多相关文章
- Codeforces Round #208 (Div. 2) A.Dima and Continuous Line
#include <iostream> #include <algorithm> #include <vector> using namespace std; in ...
- Codeforces Round #208 (Div. 2) B Dima and Text Messages
#include <iostream> #include <algorithm> #include <string> using namespace std; in ...
- Codeforces Round #208 (Div. 2)
A - Dima and Continuous Line 水题:直接模拟: #include<cstdio> #define maxn 1005 using namespace std; ...
- Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合
题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #214 (Div. 2) C. Dima and Salad (背包变形)
C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #214 (Div. 2) C. Dima and Salad 背包
C. Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to ...
- Codeforces Round #324 (Div. 2)D. Dima and Lisa 数学(素数)
D. Dima and Lisa Dima loves representing an odd num ...
- Codeforces Round #553 (Div. 2)B. Dima and a Bad XOR 思维构造+异或警告
题意: 给出一个矩阵n(<=500)*m(<=500)每一行任选一个数 异或在一起 求一个 异或在一起不为0 的每行的取值列号 思路: 异或的性质 交换律 x1^x2^x3==x3^x2 ...
随机推荐
- 【html】【3】html标签列表
必看参考: http://www.divcss5.com/html/h323.shtml http://www.w3school.com.cn/tags/tag_html.asp 常用: <ht ...
- ios专题 - 单例模式的实现
[原创]http://www.cnblogs.com/luoguoqiang1985 单例模式是什么? 一个类只有一个实例. ----------------------- 这样做有什么好处? 在我的 ...
- 分享一个在PearOS里面的plank的配置文件
plank的配置文件的路径是/home/pear/.config/plank/dock1/settings #This file auto-generated by Plank. #2013-09-0 ...
- JS字符串操作大全
String对象属性 (1) length属性 length算是字符串中非常常用的一个属性了,它的功能是获取字符串的长度.当然需要注意的是js中的中文每个汉字也只代表一个字符,这里可能跟其他语言有些不 ...
- HTML 5结构
进行总体布局时候,具体可以用的方法. 1.大纲:文档中各内容区块的结构编排. 内容区块可以使用标题元素来展示各级内容区块的标题. 关于内容区块的编排可以分为“显示编排”和“隐式编排”. 显示编排:明确 ...
- IS脚本学习
OnFirstUIBefore:函数块用于第一安装应用时安装部件前所要完成的任务.一般在这里进行下列设: 1. 设置屏蔽 2. 显示欢迎信息,软件协议书或关于软件安装的其他说明信息 3. 从用户处获取 ...
- 简单学C——第三天
控制结构(二) 前面我们已经了解到了,控制结构中的判断结构,当然switch语句也是判断语句.不过如果if...else...语句你会了,我相信switch语句你也一定会的,它们的功能都是差不 ...
- Delphi中快捷键的使用
CTRL+SHIFT+↑(↓) 在过程.函数.事件内部, 可跳跃到相应的过程.函数.事件的定义(在INTERFACE和IMPLEMENTATION之间来回切换)CTRL+J (弹出DELPHI语句提示 ...
- IbatisNet开发使用小结
一. 介绍 平常做企业级应用,需求变化是经常的事,而很多基础代码重复也是很让人头疼的问题.所以很多人会使用一些ORM框架来增强项目的可维护性.可扩展性.IBatis.Net就是一个比较易用的ORM ...
- Maven镜像配置
镜像是为了提供更快的服务 如图:X就认为是Y的一个镜像. 编辑settings.xml配置中央仓库镜像: <settings> ... <mirrors> <mirror ...