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 ...
随机推荐
- 编写适合windows 7 平台的软件,给程序添加UAC认证
Delphi程序必须在资源里面嵌入MANIFEST信息 一. 首先编辑一个文件,内容如下: <?xml version="1.0" encoding="UTF-8& ...
- help python(查看模块帮助文档)
查看模块帮助文档: help(len) -- docs for the built in len function (note here you type "len" not &q ...
- SQL Trainning 总结
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- java 反射取得方法入参类型的泛形
package TestReflectClass; import java.util.List; /** * Created by wangyang on 2016/12/16. */ public ...
- 283. Move Zeroes(C++)
283. Move Zeroes Given an array nums, write a function to move all 0's to the end of it while mainta ...
- ACM YTU 挑战编程 字符串 Problem A: WERTYU
Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...
- WPF学习(一)控件的公共属性
Visiblity控件是否可见:枚举类型:Visible表示可见.Collapsed不可见. IsEnabled:控件是否可用:bool类型. Background:背景色. FontSize:字体大 ...
- js获取上传文件信息并及时查看
<form id="picForm" name="picForm" method="post" enctype="mult ...
- swift从0加到1000(不包括1000)的五种写法
用了while, do...while, for in, for in ... { temp += i i++ } println(temp) do { temp2 += j j++ } ) prin ...
- 使用pyinstaller 2.1将python打包并添加版本信息和图标
最近用 wxpython写了一个小的脚本,因为想要发布给没有装python和wxpython的人使用,遂决定使用pyinstaller 2.1进行打包. 其中遇到几个问题: 1,给打包的文件添加图标 ...