Atcoder C - Vacation ( DP )
C - Vacation
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100100 points
Problem Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of NN days. For each ii (1≤i≤N1≤i≤N), Taro will choose one of the following activities and do it on the ii-th day:
- A: Swim in the sea. Gain aiai points of happiness.
- B: Catch bugs in the mountains. Gain bibi points of happiness.
- C: Do homework at home. Gain cici points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
- All values in input are integers.
- 1≤N≤1051≤N≤105
- 1≤ai,bi,ci≤1041≤ai,bi,ci≤104
Input
Input is given from Standard Input in the following format:
NN
a1a1 b1b1 c1c1
a2a2 b2b2 c2c2
::
aNaN bNbN cNcN
Output
Print the maximum possible total points of happiness that Taro gains.
Sample Input 1 Copy
3
10 40 70
20 50 80
30 60 90
Sample Output 1 Copy
210
If Taro does activities in the order C, B, C, he will gain 70+50+90=21070+50+90=210 points of happiness.
Sample Input 2 Copy
1
100 10 1
Sample Output 2 Copy
100
Sample Input 3 Copy
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Sample Output 3 Copy
46
Taro should do activities in the order C, A, B, A, C, B, A
题意:裸的DP题意,题面单词很简单。
思路:下一个状态选上一个状态中的不和自己相同的那两个中的最大值。
转移方程可以见代码。
我的AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll dp[maxn][]; int main()
{
gbtb;
cin>>n;
repd(i,,n)
{
cin>>a[i]>>b[i]>>c[i];
}
dp[][]=a[];
dp[][]=b[];
dp[][]=c[];
repd(i,,n)
{
dp[i][]+=max(dp[i-][],dp[i-][])+a[i];
dp[i][]+=max(dp[i-][],dp[i-][])+b[i];
dp[i][]+=max(dp[i-][],dp[i-][])+c[i];
}
cout<<max(dp[n][],max(dp[n][],dp[n][]));
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
Atcoder C - Vacation ( DP )的更多相关文章
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- Tour(dp)
Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)
Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...
- 最长公共子序列长度(dp)
/// 求两个字符串的最大公共子序列长度,最长公共子序列则并不要求连续,但要求前后顺序(dp) #include <bits/stdc++.h> using namespace std; ...
随机推荐
- Python3编写网络爬虫07-基本解析库pyquery的使用
三.pyquery 简介:同样是一个强大的网页解析工具 它提供了和jQuery类似的语法来解析HTML文档,支持CSS选择器,使用非常方便 安装: pip install pyquery 验证: im ...
- Shiro-Subject 分析
Subject反正就好像呈现的视图.所有Subject 都绑定到SecurityManager,与Subject的所有交互都会委托给SecurityManager:可以把Subject认为是一个门面: ...
- flex布局下el-table横向滚动条失效
如下图,是一种常见的页面结构,我们可以有很多方法实现,inline-block,float,flex等等 但是,最近项目中遇到一个怪事,左边是侧边栏导航,右边是一个数据展示table,el-table ...
- IO流_PrintWriter(字符打印流)与PrintStream(字节打印流)
PrintStream: 1.提供了打印方法可以对多种数据类型值进行打印,并保持数据的表示形式 2.它不抛IOException 3.构造函数接受三种类型的值: 字符串路径 File对象 ...
- BZOJ 1444:[JSOI2009]有趣的游戏
BZOJ 1444:[JSOI2009]有趣的游戏 题目链接 首先我们建出Trie图,然后高斯消元. 我们设\(f_i\)表示经过第\(i\)个点的期望次数: \[ f_x=\sum i\cdot p ...
- [NOIP2018]保卫王国
嘟嘟嘟 由于一些知道的人所知道的,不知道的人所不知道的原因,我来发NOIP2018day2T3的题解了. (好像我只是个搬运工--) 这题真可以叫做NOIplus了,跟其他几道比较水的题果然不一样,无 ...
- luogu P4718 【模板】Pollard-Rho算法(贴代码)
嘟嘟嘟 从标题中能看出来,我只是想贴一个代码. 先扯一会儿. 前几天模拟考到了这东西,今天有空就学了一下. 到网上找资料,发现前置技能是miller-rabin筛法,于是我还得先学这么个东西. 学mi ...
- erc721-165学习
ERC165: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md 就是一种发布并能检测到一个智能合约实现了什么接口的标准 这么做 ...
- Qt+Qgis二次开发:地理实体抽象
1 概述 地理实体抽象是指点.线.面及其组合而成的,用于描述实际地物的数据结构. 其中包含几何实体和属性数据. GIS中进行几何操作,以各种实体类为基础进行操作. 在OGC中,地理实体可以由WKT表 ...
- 百度云受邀成为 LF Edge 创始成员
导读 1月24日,Linux Foundation(Linux基金会,以下简称LF)宣布正式成立旗下子机构边缘计算基金会LF Edge,旨在建立边缘计算统一开源框架.百度云受邀成为创始成员. 中国公司 ...