java 数字三角形_数字三角形 Number Triangles(java的MLE解决办法)

8d8e6dc3f6528335ad075976c36055b6.png

于是在网上找相应的解决办法,如何对java的内存进行优化

于是使用了里面的IO读取加速的模板,套用了一下,就过了。。。

a81cb91551a7abb8c1013d6c234e7d1e.png

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());

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值