第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

請(qǐng)教:為什么這么一小段java代碼會(huì)使用那么多內(nèi)存?

請(qǐng)教:為什么這么一小段java代碼會(huì)使用那么多內(nèi)存?

繁星coding 2018-12-06 21:25:34
武大oj的題。題目傳送門。 以我看,我的代碼最大就開(kāi)兩個(gè)數(shù)組a[1000],b[1000],怎么會(huì)用到553728KB的內(nèi)存。提交了好多次,都是這個(gè)數(shù)量級(jí)的內(nèi)存消耗。 求大師們拉小弟一把呀:) Problem id:?1383Memory: 553728KB??Time: 6610msLanguage: Java??Result: Memory Limit Exceeded code: 1 import java.util.*; 2 import java.io.*; 3 4 public class Main 5 { 6 public static final int MAXN = 1000; 7 //public static final String INPUT = "in.txt"; 8 static int max3(int x, int y, int z) 9 { 10 return (x>y?x:y)>z?(x>y?x:y):z; 11 } 12 public static void main(String[] args) 13 { 14 /* 15 try 16 { 17 FileInputStream instream = new FileInputStream(INPUT); 18 System.setIn(instream); 19 } 20 catch(Exception e) 21 { 22 System.err.println("input error!"); 23 } 24 */ 25 int[] a = new int[MAXN]; 26 int[] b = new int[MAXN]; 27 int t,r,c,res; 28 Scanner cin = new Scanner(System.in); 29 t=cin.nextInt(); 30 for(int cas=1; cas<=t; cas++) 31 { 32 r=cin.nextInt(); 33 c=cin.nextInt(); 34 35 //initialize 36 Arrays.fill(a, 0); 37 Arrays.fill(b, 0); 38 39 if(r==1 && c==1) res=cin.nextInt(); 40 else if((r==1 && c>1) || (r>1 && c==1)) 41 { 42 int tmp = (r>c?r:c); 43 for(int i=0; i<tmp; ++i) 44 a[0]+=cin.nextInt(); 45 res=a[0]; 46 } 47 else//r,c>=2 48 { 49 for(int i=0; i<c; ++i) 50 a[i]=cin.nextInt(); 51 for(int i=0; i<c; ++i) 52 b[i]=cin.nextInt(); 53 54 for(int i=1; i<c; ++i) 55 a[i] += a[i-1]; 56 b[0]+=a[0]; 57 58 for(int i=1; i<c; ++i) 59 b[i] += max3(b[i-1], a[i-1], a[i]); 60 61 r -= 2; 62 while(r-- > 0) 63 { 64 for(int i=0; i<c; ++i) 65 a[i]=cin.nextInt(); 66 67 a[0]+=b[0]; 68 for(int i=1; i<c; ++i) 69 a[i] += max3(a[i-1], b[i-1], b[i]); 70 for(int i=1; i<c; ++i) 71 b[i]=a[i]; 72 } 73 res=b[c-1]; 74 } 75 System.out.println("Case #"+cas+": " + res); 76 } 77 } 78 } 貌似也沒(méi)有哪里有內(nèi)存泄漏啊……
查看完整描述

目前暫無(wú)任何回答

  • 0 回答
  • 0 關(guān)注
  • 622 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)