题目:喜欢做题的 lre
思路:动态规划
代码如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class Main {
//快速输入
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//快速输出
static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
String[] s=br.readLine().split(" ");
int t=Integer.parseInt(s[0]);
for(;t>0;t--) {
s=br.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int[][] dp=new int[n+1][3];
for(int i=1;i<=n;i++) {
s=br.readLine().split(" ");
int z=Integer.parseInt(s[0]);
int p=Integer.parseInt(s[1]);
int c=Integer.parseInt(s[2]);
dp[i][0]=Math.max(dp[i-1][1], dp[i-1][2])+z;
dp[i][1]=Math.max(dp[i-1][0], dp[i-1][2])+p;
dp[i][2]=Math.max(dp[i-1][0], dp[i-1][1])+c;
}
int ans=Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2]));
pw.println(ans);
}
pw.flush();
}
}