Тёмный

[CSES][Introductory Problems] Grid Paths 

NeatlyStructured
Подписаться 3 тыс.
Просмотров 6 тыс.
50% 1

cses.fi/proble...
In this problem we need to find the number of valid paths from the upper left corner to the lower left corner in a 7x7 grid using move UP, DOWN, RIGHT, and LEFT. We prune the search space by removing branches that create multiple components of unvisited cells.

Опубликовано:

 

10 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 61   
@ayushagrawal2816
@ayushagrawal2816 3 года назад
you done a great work man really your explanation make me feel what is the issue in the problem
@neatlystructured
@neatlystructured 3 года назад
Glad it helped!
@stark_mark1107
@stark_mark1107 3 года назад
Great work, man!! Loved the animation. It made understanding the solution a lot easier. And this definitely isn't an introductory problem.
@neatlystructured
@neatlystructured 3 года назад
Glad it helped! you are right this problem was pretty hard!
@ahmedheakl5181
@ahmedheakl5181 2 года назад
Great work sir. You are the BEST!
@neatlystructured
@neatlystructured 2 года назад
thank you so much!
@peterraafat6610
@peterraafat6610 2 года назад
How does the pruning decreases the time complexity? I think it's over complicating to handle all these cases.
@neatlystructured
@neatlystructured 2 года назад
without pruning we could not solve the problem in a timely manner. Can you do it without all the cases?
@auravstomar7629
@auravstomar7629 2 года назад
Awesome work!
@neatlystructured
@neatlystructured 2 года назад
thank you so much!
@piyushmishra316
@piyushmishra316 3 года назад
Could you give some tip on how did you make that animation? I think it could be very helpful in coming up with issues in our solution, than trying to figure out issues through Debug logs. Any link or tip on visualising the algorithm will be very helpful. Anyways, great explanation, thanks a lot, and keep up the good work.
@neatlystructured
@neatlystructured 3 года назад
I used Processing IDE. It is very to use once you get the basics of it. I recommend you watch some tutorials and then try implementing what comes to mind. I tried looking for the code for this animation but i couldnt find it. I ll keep looking for it.
@piyushmishra316
@piyushmishra316 3 года назад
@@neatlystructured Wow, thats a neat software i didn't know about. Now that i think, I guess one could also use game engines for visualising such patterns. Take a cube, and take a grid of possible locations to move, a delta time, and let the DFS algorithm keep finding coordinates in the background. Anyways, thanks a lot for info on Processing IDE.
@neatlystructured
@neatlystructured 3 года назад
Exaactly, it may be a little overkill since you wont need the physics engine much. That s why Processing is ideal for basic tasks like this!
@amitwithglasses
@amitwithglasses 3 года назад
really nice explanation, understood it but I don't think I'll be able to solve it in an interview
@neatlystructured
@neatlystructured 3 года назад
The number of problems you can solve on your own from scratch is proportional to the number of problems you ve seen before. The best thing to do after solving a new problem is to think of variations of it (like in this case different starting and finishing positions....) and add these to your database of problems. Very rare are the times where one does something truly innovative, most of the time we just recycle what we ve learned, that's why we have to learn a lot!
@ugthesep5706
@ugthesep5706 15 дней назад
@@neatlystructured true all the problems we can solve is because we have seen/know the concept using to solve that problem until you are not a genius
@rfwdsffsfdws8578
@rfwdsffsfdws8578 Год назад
Can you explain why 88418 path ? I just want to know how to calculate that number using math.
@alphagoai5237
@alphagoai5237 3 года назад
can you please make a video on prime tuples(from mathematics section of cses) i tried using bitmasking it give tle in 2 cases
@neatlystructured
@neatlystructured 3 года назад
I ll make a video for all cses problems, i was planning on solving section by section. But since you requested this problem, i will make a video about it asap. Stay tuned!
@VishalGupta-xw2rp
@VishalGupta-xw2rp 11 месяцев назад
Amazing... Learnt alot ❤
@neatlystructured
@neatlystructured 10 месяцев назад
Glad to hear that!
@anirudhrawat7584
@anirudhrawat7584 2 года назад
Thanks for the explanation
@neatlystructured
@neatlystructured 2 года назад
glad you liked it!
@aaryanjain3422
@aaryanjain3422 2 месяца назад
#include #define int long long int #define F first #define S second #define pb push_back #define RIGHT 0 #define LEFT 1 #define DOWN 2 #define UP 3 #define isValid(a,b,c) (a>=b && a < c ? 1: 0) using namespace std; int dx[4] = {0,0,1,-1}; int dy[4] = {1,-1,0,0}; string str; int vis[7][7]; void solve() { } int countPaths(int x,int y, int pos) { if(pos == (int)str.length()) return (x==6 && y==0); if(x == 6 && y == 0) return 0; if(vis[x][y]) return 0; vector visited(4,-1); for(int k = 0; k < 4; k++) { if(isValid(x + dx[k],0,7) && isValid(y + dy[k],0,7)) visited[k] = vis[x + dx[k]][y+dy[k]]; } if(!visited[DOWN] && !visited[UP] && visited[RIGHT] && visited[LEFT]) return 0; if(!visited[RIGHT] && !visited[LEFT] && visited[DOWN] && visited[UP]) return 0; if(isValid(x-1,0,7) && isValid(y+1,0,7) && vis[x-1][y+1]==1) { if(!visited[RIGHT] && !visited[UP]) return 0; } if(isValid(x+1,0,7) && isValid(y+1,0,7) && vis[x+1][y+1]==1) { if(!visited[RIGHT] && !visited[DOWN]) return 0; } if(isValid(x-1,0,7) && isValid(y-1,0,7) && vis[x-1][y-1]==1) { if(!visited[LEFT] && !visited[UP]) return 0; } if(isValid(x+1,0,7) && isValid(y-1,0,7) && vis[x+1][y-1]==1) { if(!visited[LEFT] && !visited[DOWN]) return 0; } vis[x][y] = 1; int numOfPaths = 0; if(str[pos] == '?') { for(int k = 0; k < 4; k++) { if(isValid(x+dx[k],0,7) && isValid(y+dy[k],0,7)) numOfPaths += countPaths(x+dx[k], y+dy[k], pos+1); } } else if(str[pos] == 'R' && y + 1 < 7) numOfPaths+= countPaths(x,y+1,pos+1); else if(str[pos] == 'L' && y -1 >= 0) numOfPaths+= countPaths(x,y-1,pos+1); else if(str[pos] == 'U' && x -1 >= 0) numOfPaths+= countPaths(x-1,y,pos+1); else if(str[pos] == 'D' && x + 1 < 7) numOfPaths+= countPaths(x+1,y,pos+1); vis[x][y] = 0; return numOfPaths; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif cin >> str; cout
@tonymontaro
@tonymontaro 2 года назад
Beautiful, thanks!
@neatlystructured
@neatlystructured 2 года назад
thank you very much!
@ambujbhaskar9288
@ambujbhaskar9288 3 года назад
great video, nice explaination
@neatlystructured
@neatlystructured 3 года назад
Thank you very much!
@barkbarkbark198
@barkbarkbark198 3 года назад
Very cool cases thank you
@neatlystructured
@neatlystructured 3 года назад
Thank you !
@jeb9472
@jeb9472 Год назад
thank you very much, sir
@erenyeager4452
@erenyeager4452 3 года назад
It would be good if you could attach your solution too. Anyway thanks for the video
@neatlystructured
@neatlystructured 3 года назад
I think attaching a solution makes it so easy for one to just copy and paste it that they wont learn anything. Don't you think so? How could attaching a solution be beneficial to the learning process?
@erenyeager4452
@erenyeager4452 3 года назад
@@neatlystructured If someone really wanted to copy paste a solution he wouldn't have searched for this video. I needed code for debugging. After two hours I found a single wrong in solution currently I am at 1.5 seconds still have to prune it.
@neatlystructured
@neatlystructured 3 года назад
I am sorry for the inconvenience, here is the link to my solution. cses.fi/paste/e4cdcac2b8330df51f2273/
@erenyeager4452
@erenyeager4452 3 года назад
@@neatlystructured Hey I have done it man. thanks anyway
@ishmam8643
@ishmam8643 3 года назад
Bro, Thanks a lot, ur too awesome.
@neatlystructured
@neatlystructured 3 года назад
Thaank you very much!
@yadnyadeepkhadke8039
@yadnyadeepkhadke8039 2 года назад
Thanks !!
@mrdude1084
@mrdude1084 3 года назад
Awesome!
@neatlystructured
@neatlystructured 3 года назад
Thank you very much!
@_rkc
@_rkc 3 года назад
very nice
@neatlystructured
@neatlystructured 2 года назад
Thank you!
@nhatminhtran2270
@nhatminhtran2270 3 года назад
Tks bro
@neatlystructured
@neatlystructured 3 года назад
Welcome!
@didyoustealmyfood8729
@didyoustealmyfood8729 3 года назад
thansk dud
@neatlystructured
@neatlystructured 3 года назад
Welcome!
@alaymehta2449
@alaymehta2449 3 года назад
Gud one
@neatlystructured
@neatlystructured 3 года назад
Thank you!
@navitabatra3019
@navitabatra3019 3 года назад
👌👌👌
@neatlystructured
@neatlystructured 3 года назад
Thank you!
@adityavikramsinha408
@adityavikramsinha408 10 месяцев назад
damn. DAMN. damn.
@neatlystructured
@neatlystructured 10 месяцев назад
What's wrong?
@adityavikramsinha408
@adityavikramsinha408 10 месяцев назад
@@neatlystructured nOo it's a very good visualisation
@neatlystructured
@neatlystructured 10 месяцев назад
Glad you liked it! Make sure to spread the word
@uddiptakalita3006
@uddiptakalita3006 Год назад
can any1 share the AC code plz
@arifmulani7130
@arifmulani7130 10 месяцев назад
#include using namespace std; int isValid(int a,int b,int c) {return (a>=b && a
@samarsinghai4405
@samarsinghai4405 9 месяцев назад
Still giving TLE
@neatlystructured
@neatlystructured 9 месяцев назад
How is that possible?
@abdulrahmanabdulkareem1039
@abdulrahmanabdulkareem1039 8 месяцев назад
I don't know but I have the same issue @@neatlystructured
Далее
[CSES][Dynamic Programming] Counting Towers
24:44
Просмотров 6 тыс.
[CSES][Sorting and Searching] Room Allocation
24:32
Просмотров 3,9 тыс.
ОНА ОПЯТЬ ПОЁТ 😱
3:05:53
Просмотров 1,1 млн
WHY IS THE HEAP SO SLOW?
17:53
Просмотров 234 тыс.
CSES - Digit Queries
19:03
Просмотров 4,8 тыс.
Use Arc Instead of Vec
15:21
Просмотров 148 тыс.
[CSES][Dynamic Programming] Elevator rides
23:33
Просмотров 3 тыс.
[CSES][Dynamic Programming] Array Description
13:08
Просмотров 7 тыс.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Vim Tips I Wish I Knew Earlier
23:00
Просмотров 69 тыс.