rebel_roar's blog

By rebel_roar, history, 5 months ago, In English

I am trying DP questions from a while but still i stuck in some questions Please clear my small doubt, Let's say in any DP question i need to make a dp matrix by considering a value in the row and another one in the column. My confusion is which one i should put in row and which one i should put in the column or i can put any of them at any place because in knapsack problem i can use any parameter in both row or column Here Using number of itmes in the row and here Using total weight in the row.

Thank you.

Read more »

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

By rebel_roar, history, 6 months ago, In English

Can anyone help me, which is more efficient while using in the for loop?

for(u = 2; u <= sqrt(n); u++)


for(u = 2; u*u <= n; u++)

Here are my both submission

Using first method — 119098252

Using second method — 119098208

While using the first method i got TLE but the same code using with the second method got Accepted..

I am assuming that method one is calculating sqrt(n) again and again and other one is calculating u*u again and again then why one is got accepted other one is not.

Please tell me the reason behind this?

Read more »

  • Vote: I like it
  • +22
  • Vote: I do not like it