于是在网上找相应的解决办法,如何对java的内存进行优化
于是使用了里面的IO读取加速的模板,套用了一下,就过了。。。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
static InputReader in;
static PrintWriter out;
static int dp[][] = new int[1001][1001];
public static void main(String[] args) throws IOException {
//Scanner cin = new Scanner(System.in);
in = new InputReader(System.in);
out = new PrintWriter(System.out);
int r = in.nextInt();
int t;
for(int i=1;i<=r;i++) {
for(int j=1;j<=i;j++) {
t = in.nextInt();
dp[i][j] = Math.max(dp[i-1][j-1],dp[i-1][j])+t;
}
}
int ans = 0;
for(int i=1;i<=r;i++) {
ans = Math.max(ans, dp[r][i]);
}
System.out.println(ans);
out.close();
}
static class InputReader {
BufferedReader br;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public int nextInt() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
int x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public long nextLong() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
long x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public String next() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
StringBuilder sb = new StringBuilder();
while (c > 32) {
sb.append((char) c);
c = br.read();
}
return sb.toString();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
}