using
System;
class
Program {
static
int
[, ] dp =
new
int
[100001, 4];
static
int
Sub(
int
[, ] points,
int
last,
int
index)
{
if
(index == points.GetLength(0))
return
0;
if
(dp[index, last] != -1)
return
dp[index, last];
int
ans = 0;
if
(last == 0) {
ans = Math.Max(
ans,
Math.Max(
points[index, 0]
+ Sub(points, 1, index + 1),
Math.Max(
points[index, 1]
+ Sub(points, 2, index + 1),
points[index, 2]
+ Sub(points, 3, index + 1))));
}
else
if
(last == 1) {
ans = Math.Max(
ans,
Math.Max(points[index, 1]
+ Sub(points, 2, index + 1),
points[index, 2]
+ Sub(points, 3, index + 1)));
}
else
if
(last == 2) {
ans = Math.Max(
ans,
Math.Max(points[index, 0]
+ Sub(points, 1, index + 1),
points[index, 2]
+ Sub(points, 3, index + 1)));
}
else
{
ans = Math.Max(
ans,
Math.Max(points[index, 1]
+ Sub(points, 2, index + 1),
points[index, 0]
+ Sub(points, 1, index + 1)));
}
return
dp[index, last] = ans;
}
static
void
Main()
{
int
[, ] points
= { { 1, 2, 5 }, { 3, 1, 1 }, { 3, 3, 3 } };
for
(
int
i = 0; i < dp.GetLength(0); i++) {
for
(
int
j = 0; j < dp.GetLength(1); j++) {
dp[i, j] = -1;
}
}
Console.WriteLine(
"Maximum Points We Can Make: "
+ Sub(points, 0, 0));
}
}