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 ...
随机推荐
- JavaScript获取网页属性包括宽、高等
function getWindowInfo() {var s = ""; s += " 网页可见区域宽:"+ document.body.clientWidt ...
- 淘宝链接中的spm参数
什么是SPM SPM是淘宝社区电商业务(xTao)为外部合作伙伴(外站)提供的一套跟踪引导成交效果数据的解决方案. 下面是一个跟踪点击到宝贝详情页的引导成交效果数据的SPM示例: http://det ...
- [Introduction to programming in Java 笔记] 1.3.8 Gambler's ruin simulation 赌徒破产模拟
赌徒赢得机会有多大? public class Gambler { public static void main(String[] args) { // Run T experiments that ...
- 5shift shell
echo offcopy %systemroot%\system32\taskmgr.exe %systemroot%\system32\sethc.execopy %systemroot%\syst ...
- excel 无法打开文件,提示:向程序发送命令时出现问题
以下的方法以Excel为例,请一个一个的使用,总会有一个适合你的. 1 .兼容性 鼠标右击桌面Excel(或其他)的快捷方式,选“兼容性”,把以管理员身份运行此程序前的勾去掉,就一切ok 了. 如果桌 ...
- PHP实战开发教程
对于PHP初学者来说,一上手就学习庞大的PHP语法无疑很打击自信心.其实即便是很熟练的程序员,也未必对所有的语法非常熟悉.通常熟练的程序员比普通的程序员的优势在于对基本语法的理解非常透彻,而且常用的一 ...
- easy UI demo 含数据库加载示例
easyUI 部分代码在Googlecode 托管时而被抢此文件包含了所有官方demo,作为备份 下载地址http://pan.baidu.com/s/1pJ9hS5H
- Google开源库-Volley
Android平台的网络通信库,使是网通信 更快,更简单,更健壮 适合场景: 数据量不大,通信 频繁. 大数据,流媒体是不适合使用的 * 它主要是帮我们载入和缓存从远程网络加载的图片 * 所有的 ...
- Makefile的简单例子
1.生成test可执行文件,源文件有prog.c prog.h cord.h test:prog.o code.o gcc -o test prog.o code.o prog.o:prog.c pr ...
- VisualSVN Server 从此告别SVN记事本配置
http://www.visualsvn.com/downloads/ 注意下载的是Server版本,他还会提供一个visual Studio的插件: 安装完毕后,可以在管理界面进行角色添加,创建 ...