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; ...
随机推荐
- 【Ansible 文档】【译文】Playbooks 变量
Variables 变量 自动化的存在使得重复的做事情变得很容易,但是我们的系统不可能完全一样. 在某些系统中,你可能想要设置一些与其他系统不一样的行为和配置. 同样地,远程系统的行为和状态也可以影响 ...
- oracle sqlplus 回退键以及上下键
Linux中安装完Oracle后,默认的 sqlplus 上下键是不能用的,安装了 rlwrap 之后就能通过上下键翻回历史命令了 下载地址 https://github.com/hanslub42/ ...
- BZOJ1935:[SHOI2007]Tree 园丁的烦恼(CDQ分治)
Description 很久很久以前,在遥远的大陆上有一个美丽的国家.统治着这个美丽国家的国王是一个园艺爱好者,在他的皇家花园里种植着各种奇花异草.有一天国王漫步在花园里,若有所思,他问一个园丁道: ...
- 【JDK和Open JDK】平常使用的JDK和Open JDK有什么区别(转)
文章转自https://www.cnblogs.com/sxdcgaq8080/p/7487369.html 注意到这个问题,是在CentOS7上安装JDK的时候,查找相关的资料,发现安装JDK之前都 ...
- Linux中添加、修改和删除用户和用户组
宽为限 紧用功 功夫到 滞塞通 一.用户: 在创建用户时,需要为新建用户指定一用户组,如果不指定其用户所属的工作组,自动会生成一个与用户名同名的工作组.创建用户user1的时候指定其所属工作组user ...
- Objective-C weak深入理解
1.weak是弱引用,所引用的对象计数不会加1. 2.weak变量在其引用的对象被销毁之后,会被置为nil. 3.weak通常用于block, delegate, NSTimer,以解决循环引用带来的 ...
- HTML 图片轮播制作工具
下载地址:http://wowslider.com/download/wowslider-win-setup.zip?utm_source=free_downl_win&utm_medium= ...
- Flask源码解读--所有可扩展点
一.前言 flask中有很多可扩展点(笔者这样称呼),其中包含了信号和请求钩子,这些信号和钩子有什么用呢?其主要作用用于帮助我们进行程序的耦合性,当然还可以让我们自定义一些行为.话不多说,通过阅读源码 ...
- python语言程序设计8
1, 说实话,我挺伤心的,感觉 有点像烂剧里的主演...也许我早几天明白的话,会不会结果会不一样?但是之前还真没往这方面想过,但是确实是开了一个口子了,也不急吧.努力把现在的事给做好,变帅变高,那很 ...
- BugkuCTF 你必须让他停下
前言 写了这么久的web题,算是把它基础部分都刷完了一遍,以下的几天将持续更新BugkuCTF WEB部分的题解,为了不影响阅读,所以每道题的题解都以单独一篇文章的形式发表,感谢大家一直以来的支持和理 ...