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

Copy
3
10 40 70
20 50 80
30 60 90

Sample Output 1 Copy

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

Copy
1
100 10 1

Sample Output 2 Copy

Copy
100

Sample Input 3 Copy

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

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 )的更多相关文章

  1. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  2. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  3. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  4. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  5. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  6. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  7. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

  8. Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)

    Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...

  9. 最长公共子序列长度(dp)

    /// 求两个字符串的最大公共子序列长度,最长公共子序列则并不要求连续,但要求前后顺序(dp) #include <bits/stdc++.h> using namespace std; ...

随机推荐

  1. 前端性能优化成神之路--图片懒加载(lazyload image)

    图片懒加载(当然不仅限于图片,还可以有视频,flash)也是一种优化前端性能的方式.使用懒加载可以想要看图片时才加载图片,而不是一次性加载所有的图片,从而在一定程度从减少服务端的请求 什么是懒加载 懒 ...

  2. 洛谷P4551 最长异或路径

    传送门:https://www.luogu.org/problem/show?pid=4551 在看这道题之前,我们应懂这道题怎么做:给定n个数和一个数m,求m和哪一个数的异或值最大. 一种很不错的做 ...

  3. 【转】理解js中的原型链,prototype与__proto__的关系

    说到prototype,就不得不先说下new的过程. 我们先看看这样一段代码: 1 <script type="text/javascript"> 2 var Pers ...

  4. Spring任务调度器之Task的使用(转)

    文章转自 http://blog.csdn.net/l454822901/article/details/51829307 最近发现真的凹凸了,spring升级到3后原来已经自带任务调度器了,之前还一 ...

  5. AI 循环神经网络(RNN)

    循环神经网络(Recurrent Neural Network,简称RNN),通常用于处理序列数据.正如卷积神经网络通常用于处理网格数据(例如图像)一样. 1.展开计算图 输入.输出.记忆 权值 2. ...

  6. QWidget设置背景颜色

    如果widget是子窗口首先要添加一句: this->setAttribute(Qt::WA_StyledBackground,true); this->setStyleSheet(&qu ...

  7. jmeter(十三)常见问题及解决方法

    jmeter作为一个开源的纯Java性能测试工具,工作中极大的方便了我们进行接口.性能测试,但使用过程中也遇到了很多的问题,下面就记录一下自己遇到的问题,后续会不断更新... 1.获取日志 在使用jm ...

  8. Omi框架学习之旅 - 组件 及原理说明

    hello world demo看完后其实基本的写法就会了. 但是omi中的组件是神马鬼?其实我也不知道组件是啥. 百度百科是这么说的: 是对数据和方法的简单封装.es6中,一个类其实也可以做到对方法 ...

  9. java 之UDP编程

    大白话:每一台电脑都有自己的ip地址,向指定的ip地址发数据,数据就发送到了指定的电脑.UDP通信只是一种通信方式而已,其特点就不多说.有了ip地址数据就能发送到指定的电脑了,但是呢!我把数据发送到电 ...

  10. 【webstorm】注册码 更新笔记

    20190225 1.修改hosts文件,windows的hosts文件路径是  C:\ Windows \ System32 \ drivers \ etc \ hosts 0.0.0.0 acco ...