-
[1456] Orianna
- 时间限制: 1000 ms 内存限制: 65535 K
- 问题描述
-
Orianna is the lady of clockwork that fights in League of Legends. She fights with her ball.
Today, Corin, Orianna's father builds a new ball for her.
That ball contains 5 levels attack mode named M1, M2, M3, M4 and M5. But there's a strange rule in using the mode - once she attack in one mode and the previous attack is in a lower mode, she can only use a lower mode than this time in the next attack. Other wise, when she attack in one mode and the previous one is in a higher mode, she can only use a higher mode than this time in the next attack.
For example, her previous attack is using M3 and her current mode is M4, then she can only use M1, M2, M3in the next attack.
Since all kinds of reasons (physical condition, mentation, etc.), the damage of each attack in each mode of each time in one competition is different.
Give you the damage of each attack in each mode of each time in one competition, you should help Orianna to design an attack planning that makes the damage maximum.
- 输入
-
This problem contains several cases. The first line of each case is an integer N, indicates the number of times that Orianna should attack. (4 ≤ N ≤ 100000).
Next follow 5 lines, indicate M1, M2, M3, M4 and M5. Each line contains N integers that means the ith attack damage if using this mode. Each single damage will not exceeds 1000. - 输出
-
For each case, you should output the maximum damage.
- 样例输入
-
5 3 2 1 4 1 2 3 3 1 2 4 1 2 3 1 2 4 2 1 3 2 1 2 3 4
- 样例输出
-
17
- 提示
-
无
- 来源
-
XadillaX
题意:发条魔灵-奥莉安娜的爸爸给她造了五个球,每次攻击时每个球都有特定的伤害,当上次攻击用的球的编号小于此次攻击用的球的编号时,那么下次攻击用的球的编号要小于此
次攻击用的球的编号。当上次攻击用的球的编号大于此次攻击用的球的编号时,那么下次攻击用的球的编号要大于此次攻击用的球的编号。求N次攻击造成的最大的伤害。
分析:DP
dp[i][j][0]表示第 i 次攻击时第 j 个球的下个球编号要小于 j,也就是说第 j 个球的状态是下降
dp[i][j][1]表示第 i 次攻击时第 j 个球的下个球编号要大于 j,也就是说第 j 个球的状态是上升
那么当前的这个球的上升状态必定是由上次的那个球的下降状态转移过来的,并且,上次那个球的状态要大于这次的编号
#pragma comprint(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<vector> #include<map> #include<stdlib.h> #include<time.h> #include<algorithm> #define LL __int64 #define FIN freopen("in.txt","r",stdin) using namespace std; const int MAXN=100000+5; const int INF=0x3f3f3f3f; int dp[MAXN][6][2]; int a[10+5][MAXN]; int main() { int n; while(scanf("%d",&n)!=EOF) { memset(dp,0,sizeof(dp)); for(int i=1;i<=5;i++) { for(int j=1;j<=n;j++) scanf("%d",&a[i][j]); } for(int i=1;i<=5;i++) { dp[1][i][0]=dp[1][i][1]=a[i][1]; } for(int i=2;i<=n;i++) { for(int j=1;j<=5;j++)//枚举本次球的编号 { for(int k=1;k<=5;k++)//枚举上次球的编号 { if(k>j) { dp[i][j][0]=max(dp[i][j][0],dp[i-1][k][1]+a[j][i]); } else if(k<j) { dp[i][j][1]=max(dp[i][j][1],dp[i-1][k][0]+a[j][i]); } } } } int ans=-INF; for(int i=1;i<=5;i++) { ans=max(ans,max(dp[n][i][1],dp[n][i][0])); } printf("%d ",ans); } return 0; }