arrrhh's blog

By arrrhh, history, 10 years ago, In English

Hello everyone. I was doing the problem Dima and Salad http://codeforces.me/problemset/problem/366/C and this is the recursive memoized solution that I came up with

rec(int tasteNow, int caloriesNow, int index)

so from here we can go to index+1 choosing fruit at index or index+1 without choosing fruit at index

 static int rec(int tasteNow, int caloriesNow, int index)    // will return maximum taste among all permissible 
	  {
		  int rem = 0;
		  int quo = 0;
		  if (caloriesNow > 0){
			  rem = tasteNow%caloriesNow;
		  	  quo = tasteNow/caloriesNow;
		  }
		  
		  if (rem == 0 && quo == k)
			  dptaste[index] = Math.max(dptaste[index], tasteNow);
		  
		  if (index >= n)
			  return 0;
		  if (dptaste[index] != -1)
			  return dptaste[index];
		  
		  int res = 0;
		  res =  Math.max(res, Math.max(rec(tasteNow+taste[index], caloriesNow+calories[index], index+1), rec(tasteNow, caloriesNow, index+1)));
		  
		  dptaste[index] = Math.max(dptaste[index], res);
		  return dptaste[index];
		  
		  
		  
	  }

Can someone tell me what is wrong with my approach and how I can modify it to get the correct solution. Thanks

  • Vote: I like it
  • -4
  • Vote: I do not like it

| Write comment?
»
10 years ago, hide # |
 
Vote: I like it -7 Vote: I do not like it

Коды на оружие, розыск, снаряжение: LXGIWYL — набор оружия №1 (дробовик, мини-MP5, AK-47, винтовка, бита, пистолет 9mm, ракетная установка, коктейль Молотова, баллончик с краской, кастет) KJKSZPJ — набор оружия №2 (пистолет Desert Eagle, Sawed-Off, Tec-9, нож, автомат M4, снайперская винтовка, огнетушитель, огнемет, гранаты) UZUMYMW — набор оружия №3 (автомат M4, цепная бензопила, пистолет 9mm с глушителем, Spaz, MP5, снайперская винтовка, тепловая RPG, мины.) Коды на здоровье, деньги, предметы: HESOYAM — здоровье, броня, $250.000, бесплатный ремонт автомобиля (нужно находиться в машине) OSRBLHH — увеличить на две звезды уровень вашей преступности ASNAEB — очистить уровень вашей преступности в полиции (код от ментов) LJSPQK — уровень вашей преступности — 6 звезд WANRLTW, FULLCLIP — бесконечные патроны, без перезарядки AEZAKMI — вас никогда не разыскивают OUIQDMW — полный боекомплект при вождении FOOOXFT — у всех есть оружие NCSGDAG — уровень Hitman по всем навыкам владения оружием AIYPWZQP — получить парашют