|
|
back to boardwhat is the problem? # include <stdio.h> # include <conio.h> # include <math.h> # include <stdlib.h> # include <time.h> # include <limits.h> bubble( int a[] , int n ) { int i , j , t;
for( i = n - 1 ; i >= 1 ; i-- ) for( j = 1 ; j <= i ; j++ ) if( a[j - 1] > a[j] ){ t = a[j - 1]; a[j - 1] = a[j]; a[j] = t; } } int bul_( int *dizi , int optimum , int adet ) { static int min = INT_MAX; int i; min = min < optimum ? min : optimum ; if( dizi[0] > optimum ) return; if( adet == 0 && dizi[0] < optimum ) min = min < optimum - dizi[0] ? min : optimum - dizi[0] ; for( i = 0 ; i < adet ; ++i ) bul_( dizi + i + 1 , optimum - dizi[0] , adet - i - 1 );
return min; } int main() { int dizi[100] , adet , i , optimum , toplam = 0 , deger; scanf("%i",&adet); for( i = 0 ; i < adet ; ++i ){ scanf("%i",&dizi[i]); toplam += dizi[i]; } bubble( dizi , adet ); optimum = toplam / 2; deger = bul_( dizi , optimum , adet ); printf("%i",toplam % 2 == 0 ? deger * 2 : 2 * deger + 1 ); system("pause"); return 0; }
this code solve only four test case
|
|
|