https://drive.google.com/file/d/0Bx5rS3UK4eL-WXpFbVBLNjhYdkE/view?usp=sharing
18 noviembre 2016
02 octubre 2016
01 septiembre 2016
bd
https://drive.google.com/folderview?id=0Bx5rS3UK4eL-VkpSaW9rUUpCYW8&usp=sharing
https://drive.google.com/folderview?id=0Bx5rS3UK4eL-VkpSaW9rUUpCYW8&usp=sharing
https://drive.google.com/open?id=0Bx5rS3UK4eL-ZktfSmdDczN5ZlE
https://drive.google.com/open?id=0Bx5rS3UK4eL-ZktfSmdDczN5ZlE
NE--
https://drive.google.com/folderview?id=0Bx5rS3UK4eL-UWp0Q21UVmdtYTA&usp=sharing
https://drive.google.com/folderview?id=0Bx5rS3UK4eL-VkpSaW9rUUpCYW8&usp=sharing
https://drive.google.com/open?id=0Bx5rS3UK4eL-ZktfSmdDczN5ZlE
https://drive.google.com/open?id=0Bx5rS3UK4eL-ZktfSmdDczN5ZlE
NE--
https://drive.google.com/folderview?id=0Bx5rS3UK4eL-UWp0Q21UVmdtYTA&usp=sharing
24 mayo 2016
19 abril 2016
08 febrero 2016
subarray
public class Labs {
public static void main(String args[]){
maxSubArray resp;
maxSubArray respx;
int A[]={13,-3,-25,20,-3,-16,-23,18,20,-7,12,-5,-22,15,-4,7};
int B[]={5,-6,2,6,3,-9,1};
resp=maxSubArrayBrute(A,0,A.length);
System.out.println("I="+resp.Izq+" D="+resp.Der+" s="+resp.Sum);
respx=FIND_MAXIMUM_SUBARRAY(A,0,A.length-1);
System.out.println("I="+respx.Izq+" D="+respx.Der+" s="+respx.Sum);
}
static maxSubArray maxSubArrayBrute(int A[], int low, int high) {
maxSubArray resp=new maxSubArray(0,0,Integer.MIN_VALUE);
//max_subarray result = {0, 0, INT_MIN};
for (int i = low; i < high; i++) {
int sumTemp = 0;
for (int j = i; j < high; j++) {
sumTemp += A[j];
if (resp.Sum < sumTemp) {
resp.Izq = i;
resp.Der = j;
resp.Sum = sumTemp;
}
}
}
return resp;
}
static maxSubArray FIND_MAX_CROSSING_SUBARRAY(int A[],int low,int mid,int high){
int left_sum=Integer.MIN_VALUE;
int max_left=0;
int sum=0;
for(int i=mid;low<=i;i--){
sum+=A[i];
if(sum>left_sum){
left_sum=sum;
max_left=i;
}
}
int right_sum=Integer.MIN_VALUE;
int max_right=0;
sum=0;
for(int j=mid+1;j<=high;j++){
sum+=A[j];
if(sum>right_sum){
right_sum=sum;
max_right=j;
}
}
return new maxSubArray(max_left,max_right,left_sum+right_sum);
}
static maxSubArray FIND_MAXIMUM_SUBARRAY(int A[],int low,int high){
if(low==high)
return new maxSubArray(low,high,A[low]);
else{
int mid=(low+high)/2;
maxSubArray L = FIND_MAXIMUM_SUBARRAY(A,low,mid);
maxSubArray R = FIND_MAXIMUM_SUBARRAY(A,mid+1,high);
maxSubArray C = FIND_MAX_CROSSING_SUBARRAY(A,low,mid,high);
if(L.Sum>=R.Sum && L.Sum>= C.Sum){
return L;
}else
if(R.Sum>=L.Sum && R.Sum>=C.Sum){
return R;
}else{
return C;
}
}
}
}
class maxSubArray{
int Izq;
int Der;
int Sum;
maxSubArray(int i,int d, int s){
Izq=i;Der=d;Sum=s;
}
}
Suscribirse a:
Entradas (Atom)