Recursion 2

Páginas: 3 (734 palabras) Publicado: 7 de septiembre de 2011
groupSum – Recursion 2:

public boolean groupSum(int start, int[] nums, int target) {
  if (start >= nums.length) return (target == 0);
  if (groupSum(start + 1, nums, target - nums[start]))return true;
  if (groupSum(start + 1, nums, target)) return true;
  return false;
}

groupSum6 – Recursion 2:

public boolean groupSum6(int start, int[] nums, int target) {
   if(start>= nums.length)
      return (target == 0);
   
   int diff = target - (6 * count6(start, nums));
   if(groupSum(start, nums, diff))
      return true;
   return false;
 
}
public intcount6(int start, int [] nums)
{
   int count = 0;
   if(nums[start] == 6)
   {
      count++;
      nums[start] = 0;
   }
   if(start + 1 < nums.length)
      count += count6(start + 1, nums);   return count;
}
public boolean groupSum(int start, int[] nums, int target) {
  if (start >= nums.length) return (target == 0);
  if (groupSum(start + 1, nums, target - nums[start]))return true;
  if (groupSum(start + 1, nums, target)) return true;
  return false;
}

groupNoAdj – Recursion 2:

public boolean groupNoAdj(int start, int[] nums, int target) {
  if (start >=nums.length) return (target == 0);
  if (groupNoAdj(start + 2, nums, target - nums[start])) return true;
  if (groupNoAdj(start + 1, nums, target)) return true;
  return false;
}

groupSum5 –Recursion 2:

public boolean groupSum5(int start, int[] nums, int target) {
   if(start >= nums.length)
      return (target == 0);
   
   int diff = target - (countMult5(start, nums));
  if(groupSum(start, nums, diff))
      return true;
   return false;
   
}
public int countMult5(int start, int [] nums)
{
   int sum = 0;
   if(nums[start] % 5 == 0)
   {
      sum +=nums[start];
      nums[start] = 0;
      if(start + 1 < nums.length)
         if(nums[start + 1] == 1)
            nums[start + 1] = 0;
   }
   if(start + 1 < nums.length)
      sum +=...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Recursion
  • recursion
  • Recursion
  • Recursion Assigment
  • Recursiones fibonacci
  • Recursion
  • recursion
  • recursion

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS