|
|
back to boardwhy crash answer help me Posted by aha 10 Sep 2007 13:21 hi , here is my code . why my program crashed.
/// code
import java.io.* ; import java.util.* ;
public class stonepile { public static void main(String args[]) throwsIOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str =null ;
while((str=br.readLine())!=null) { //str=br.readLine() ; StringTokenizer st = new StringTokenizer(str," ") ; String s = st.nextToken() ; int []a = new int [50] ; int []dp = new int [2000100] ; int sum= 0 ;
int n = Integer.parseInt(s) ; for ( int i = 0 ; i < n; i ++) { str = br.readLine() ; st = new StringTokenizer(str," "); s=st.nextToken() ; int m = Integer.parseInt(s) ; a[i] = m ; //sum +=m ; } dp[0] = 1 ; for ( int i = 0 ; i < n ; i++ ) { int c = a[i] ; sum+=c ; for ( int j = sum; j -c >= 0 ; j--) if ( dp[j-c]>0) dp[ j ] = 1 ; } int y = -1 ,x = -1, j= -1 , r = 20000000 ;
for ( int i = 1; i <sum+1 ; i++) if ( dp[i]>0 && dp[sum-i]>0) { x = Math.abs(i-(sum-i)); if ( r >x) r=x ; }
System.out.println(r) ; } }
}
|
|
|