{"id":292957,"date":"2019-08-04T15:00:26","date_gmt":"2019-08-04T15:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=292957"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=292957","title":{"rendered":"\u0420\u0435\u0448\u0430\u0435\u043c \u0441\u0443\u0434\u043e\u043a\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 X"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c &#171;\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c X&#187; \u041a\u043d\u0443\u0442\u0430 \u0438 \u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u0443\u0434\u043e\u043a\u0443. \u041f\u0440\u0435\u043b\u0435\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0443\u0434\u043e\u043a\u0443 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u043e \u0431\u0435\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u0442\u0435\u0445\u043d\u0438\u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0451, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441 <a href=\"https:\/\/projecteuler.net\/problem=96\">\u0437\u0430\u0434\u0430\u0447\u043a\u0438 \u0438\u0437 Project Euler<\/a>, \u0433\u0434\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442, \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c 50 \u0441\u0443\u0434\u043e\u043a\u0443. \u0418 \u0432\u0440\u043e\u0434\u0435 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043d\u0435\u0451 \u043f\u043e\u043b\u0443\u0447\u0438\u043b, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043a\u0443 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0442\u0443\u043f\u044b\u043c \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c, \u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u043d\u0435\u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0451\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432, \u043a\u0430\u043a \u0440\u0435\u0448\u0430\u044e\u0442 \u0441\u0443\u0434\u043e\u043a\u0443 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u043b\u044e\u0434\u0438, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c X, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0414\u043e\u043d\u0430\u043b\u044c\u0434\u043e\u043c \u041a\u043d\u0443\u0442\u043e\u043c.<\/p>\n<p>  <\/p>\n<h3 id=\"algoritm-x\">\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c X<\/h3>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Knuth%27s_Algorithm_X\">\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/a> \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430. \u0418\u043b\u0438, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435, \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 &#171;\u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u0430\u0437\u0437\u043b&#187;, \u0438\u043c\u0435\u044f \u0432 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0444\u043e\u0440\u043c\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043a\u0443\u0441\u043e\u0447\u043a\u043e\u0432. \u0411\u043e\u043b\u0435\u0435 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e <em>S<\/em><\/li>\n<li>\u0415\u0441\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 <em>Y<\/em> \u044d\u0442\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/li>\n<li>\u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u0437 <em>Y<\/em> \u0442\u0430\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b <em>Y*<\/em>, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 <em>S<\/em> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 <em>Y*<\/em><\/li>\n<li>\u0422\u043e \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0432 <em>Y*<\/em> \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 (\u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442) \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e <em>S<\/em>, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432 <em>Y*<\/em> \u043d\u0435\u0442 \u043f\u043e\u043f\u0430\u0440\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<br \/>  <em>S<\/em> = {1, 2, 3, 4, 5} \u0438<br \/>  <em>Y<\/em> = { <em>A<\/em> = {1, 2},<br \/>  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<em>B<\/em> = {2, 3},<br \/>  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<em>C<\/em> = {1, 5},<br \/>  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<em>D<\/em> = {1, 4},<br \/>  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<em>E<\/em> = {5} }<br \/>  \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>B<\/em>, <em>D<\/em> \u0438 <em>E<\/em> \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 \u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>S<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 X \u041a\u043d\u0443\u0442\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e <em>Y<\/em> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u0433\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c <em>Y<\/em>, \u0438 <em>A<sub>i,j<\/sub><\/em>\u00a0=\u00a01, \u0435\u0441\u043b\u0438 <em>S<sub>j<\/sub><\/em> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 <em>Y<sub>i<\/sub><\/em>. \u0422.\u0435. \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th><em>Y<sub>i<\/sub><\/em> \\ <em>S<sub>j<\/sub><\/em><\/th>\n<th>1<\/th>\n<th>2<\/th>\n<th>3<\/th>\n<th>4<\/th>\n<th>5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><em>A<\/em><\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td><em>B<\/em><\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td><em>C<\/em><\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td><em>D<\/em><\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td><em>E<\/em><\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>S<\/em> \u0438 <em>Y<\/em>; \u0441\u0442\u044d\u043a <code>Stack<\/code> \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 (\u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0439 \u0438\u043b\u0438 \u0443\u0436\u0435 \u0438\u043c\u0435\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b)<br \/> \n<ol>\n<li>\u0415\u0441\u043b\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e <em>S<\/em> \u043f\u0443\u0441\u0442\u043e\u0435 \u2014 \u043d\u0430 \u0441\u0442\u044d\u043a\u0435 \u043b\u0435\u0436\u0438\u0442 \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e <em>Y<\/em> \u043f\u0443\u0441\u0442\u043e\u0435 \u2014 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e.<\/li>\n<li>\u0418\u0449\u0435\u043c \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 <em>S<\/em> \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <em>s<\/em>, \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0438\u0437 <em>Y<\/em>. <\/li>\n<li>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0437 <em>Y<\/em> \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 <em>X<\/em>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 <em>s<\/em>.<\/li>\n<li>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>X<\/em> \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c 6-9.<\/li>\n<li>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <em>X<\/em> \u0432 \u0441\u0442\u044d\u043a <code>Stack<\/code> \u043a\u0430\u043a \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f.<\/li>\n<li>\u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>S&#8217;<\/em> \u0438 <em>Y&#8217;<\/em>: <em>S&#8217;<\/em> \u2014 \u044d\u0442\u043e <em>S<\/em>, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u044b \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435\u0441\u044f \u0432 <em>X<\/em>, <em>Y&#8217;<\/em> \u2014 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438\u0437 <em>Y<\/em>, \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 <em>X<\/em>.<\/li>\n<li>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c X \u0434\u043b\u044f <em>S&#8217;<\/em>, <em>Y&#8217;<\/em> \u0438 <code>Stack<\/code>.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043d\u0430 \u0448\u0430\u0433\u0435 7 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u2014 \u0441\u043d\u0438\u043c\u0430\u0435\u043c \u0441 \u0432\u0435\u0440\u0448\u0438\u043d\u044b <code>Stack<\/code>\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 <em>X<\/em>. \u0415\u0441\u043b\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043d\u0438 \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0433\u043e <em>X<\/em> \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0435\u0442 \u2014 \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f.<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c, \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e. \u041f\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443 \u2014 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443. \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u043a\u0441\u0442\u0430\u0442\u0438, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0441\u0442\u044d\u043a \u043d\u0435\u043f\u0443\u0441\u0442\u044b\u043c, \u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a &#171;\u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0445\u043e\u0434\u044f\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0443\u0436\u0435 \u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u043d\u0430 \u0441\u0442\u044d\u043a\u0435&#187;.<\/p>\n<p>  <\/p>\n<p>\u0422\u043e\u043d\u043a\u043e\u0441\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447, \u0433\u0434\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432 <em>Y<\/em> \u2014 &#171;\u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0435&#187;, \u0442.\u0435. \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0432\u0435\u0441\u044c\u043c\u0430 \u0440\u0430\u0437\u0440\u0435\u0436\u0435\u043d\u043d\u0430\u044f, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0438\u0441\u043a \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 \u043f\u0440\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u041a\u043d\u0443\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dancing_Links\">\u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c &#171;\u043f\u043b\u044f\u0448\u0443\u0449\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a&#187;<\/a>. \u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u0434\u0432\u0443\u0441\u0432\u044f\u0437\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430: \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0433\u0434\u0435 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0438\u0446\u044b. \u0422\u0430\u043a\u0436\u0435 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0435. \u0422\u0430\u043a\u0430\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0438\u0437 \u0440\u0430\u0437\u0440\u0435\u0436\u0435\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0437\u0430 \u0432\u0440\u0435\u043c\u044f <em>O<\/em>(1) \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 <em>O<\/em>(<em>m<\/em> * <em>n<\/em>) \u043f\u0440\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0432 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435.<\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e Ali Assaf \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 <a href=\"https:\/\/www.cs.mcgill.ca\/~aassaf9\/python\/algorithm_x.html\">\u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0443<\/a> \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0443 \u043f\u043b\u044f\u0448\u0443\u0449\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c X \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0441\u0442\u0440\u043e\u0447\u0435\u043a.<br \/>  \u0418\u0434\u0435\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0430\u043a \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u0442\u0430\u043a \u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u0430\u0445. \u0412 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0445\u0440\u0430\u043d\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u0442\u0440\u043e\u043a, \u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0438 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u2014 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432. \u041f\u0440\u0438\u0447\u0451\u043c \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0431\u0443\u0434\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e, \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u2014 \u0437\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u041a\u043d\u0443\u0442\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434 \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u0430. \u0410 \u0432\u043e\u0442 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u0442.\u043a. \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0435\u0451 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0438\u0437 \u0432\u0441\u0435\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 (\u0438 \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0435\u0433\u043e \u0438\u0437 \u0432\u0441\u0435\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u2014 \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0441\u0447\u0435\u0437\u0430\u0435\u0442 &#171;\u0441\u0430\u043c\u0430 \u0441\u043e\u0431\u043e\u0439&#187;).<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430 Julia.<br \/>  \u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"julia\">Y = Dict(     'A' =&gt; [1, 2],     'B' =&gt; [2, 3],     'C' =&gt; [1, 5],     'D' =&gt; [1, 4],     'E' =&gt; [5] )  S = Dict(     1 =&gt; Set(['A', 'C', 'D']),     2 =&gt; Set(['A', 'B']),     3 =&gt; Set(['B']),     4 =&gt; Set(['D']),     5 =&gt; Set(['C', 'E']) )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0443\u0436\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u044b\u043d\u0438\u043c\u0430\u044e\u0449\u0430\u044f \u0438\u0437 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439, \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u043c\u0435\u0441\u0442\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"julia\">function extract_intersects!(rows, columns, base_row)     buf = []     for elt in rows[base_row]         # \u0432\u044b\u043d\u0438\u043c\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0431\u0443\u0444\u0435\u0440         push!(buf, pop!(columns, elt))         # \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432         for intersecting_row in buf[end]             for other_elt in rows[intersecting_row]                 if other_elt != elt                     delete!(columns[other_elt], intersecting_row)                 end             end         end     end     return buf end  function restore_intersects!(rows, columns, base_row, buf)     # \u0443\u0434\u0430\u043b\u044f\u043b\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0441 base_row \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443, \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0434\u043e \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435     for elt in Iterators.reverse(rows[base_row])         columns[elt] = pop!(buf)         for added_row in columns[elt]             for col in rows[added_row]                 push!(columns[col], added_row)             end         end     end end<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u0438 \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043a\u0430\u043a \u043d\u0430\u0434\u043e, \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043c\u0430\u0442\u0440\u0438\u0446\u044b. \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>extract_intersects!()<\/code> \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0438\u0437 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0443\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f \u0441 <code>base_row<\/code>, \u043d\u043e \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\u0445. \u042d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432 <code>restore_intersects!()<\/code> \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0432 \u0441\u0430\u043c\u043e\u043c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u0446\u0438\u043a\u043b\u0435 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 <code>push!(columns[col], added_row)<\/code> \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>columns[col]<\/code> \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d, \u0438 \u0432\u0441\u0435 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0435 \u0432 <code>extract_intersects!()<\/code> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u044b \u043d\u0430 \u043f\u0440\u0435\u0436\u043d\u0435\u0435 \u043c\u0435\u0441\u0442\u043e.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c X:<\/p>\n<p>  <\/p>\n<pre><code class=\"julia\">function algorithm_x(rows, columns, cover = [])     if isempty(columns)         return cover     else         # \u0438\u0449\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432         m, c = findmin(Dict(k =&gt; length(v) for (k, v) in columns))         for subset in collect(columns[c])             push!(cover, subset)             # \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438             # \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435\u0441\u044f \u0432 subset \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b             buf_cols = extract_intersects!(rows, columns, subset)             s = algorithm_x(rows, columns, cover)             # \u0435\u0441\u043b\u0438 \u043d\u0430\u0448\u043b\u043e\u0441\u044c \u043d\u0435\u043f\u0443\u0441\u0442\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 - \u0433\u043e\u0442\u043e\u0432\u043e, \u0432\u044b\u0445\u043e\u0434\u0438\u043c             s == nothing || return s             restore_intersects!(rows, columns, subset, buf_cols)             pop!(cover)         end         # \u0441\u044e\u0434\u0430 \u0434\u043e\u0439\u0434\u0451\u043c \u043b\u0438\u0431\u043e \u0435\u0441\u043b\u0438 \u0432 columns[c] \u043f\u0443\u0441\u0442\u043e,         # \u043b\u0438\u0431\u043e \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u0440\u0435\u0448\u0435\u043d\u0438\u044f         return nothing     end end<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"sudoku\">\u0421\u0443\u0434\u043e\u043a\u0443<\/h3>\n<p>  <\/p>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0435\u0441\u0442\u044c, \u0434\u0435\u043b\u043e \u0437\u0430 \u043c\u0430\u043b\u044b\u043c \u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0443\u0434\u043e\u043a\u0443 \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f.<br \/>  \u0421\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0442\u044c \u0440\u0435\u0448\u0451\u043d\u043d\u043e\u0435 \u0441\u0443\u0434\u043e\u043a\u0443:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0435 \u0441\u0442\u043e\u0438\u0442 \u0446\u0438\u0444\u0440\u0430 \u043e\u0442 1 \u0434\u043e 9 (\u0438\u043b\u0438 \u0434\u043e <em>n<\/em><sup>2<\/sup>, \u0435\u0441\u043b\u0438 \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430).<\/li>\n<li>\u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0440\u0430\u0437\u0443.<\/li>\n<li>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0440\u0430\u0437\u0443.<\/li>\n<li>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u0432\u0430\u0434\u0440\u0430\u043d\u0442\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0440\u0430\u0437\u0443.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043f\u043e 1 \u0440\u0430\u0437\u0443, \u0442.\u0435. \u043e\u043d\u0438 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u0434\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u044c. \u0412 \u043d\u0451\u043c \u0440\u043e\u0432\u043d\u043e 4<em>n<\/em><sup>2<\/sup> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0435).<br \/>  \u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0438\u0441\u043b\u043e 9 \u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0438 1 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 4 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 &#171;\u043d\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442&#187; \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e &#171;\u0432 \u043a\u043b\u0435\u0442\u043a\u0435 (1,4) \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e, \u0432 1 \u0441\u0442\u0440\u043e\u043a\u0435 \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e 9, \u0432 4 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e 9, \u0432\u043e 2 \u043a\u0432\u0430\u0434\u0440\u0430\u043d\u0442\u0435 \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e 9&#187; (\u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044f \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0441\u0443\u0434\u043e\u043a\u0443 9\u00d79).<br \/>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"julia\"># \u0441\u0443\u0434\u043e\u043a\u0443 \u0437\u0430\u0434\u0430\u0451\u0442\u0441\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 9\u00d79, \u043d\u0430 \u043c\u0435\u0441\u0442\u0435 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0443\u043b\u0438 # \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0441\u0442\u0440\u043e\u043a - \u043a\u043e\u0440\u0442\u0435\u0436\u0438 \u0432\u0438\u0434\u0430 (row, col, num) # \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432: # (0, row, col) - \u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0438 row \u0438 col \u0441\u0442\u043e\u0438\u0442 \u0447\u0438\u0441\u043b\u043e # (1, row, num) - \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 row \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e num # (2, col, num) - \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 col \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e num # (3, q, num) - \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u043d\u0442\u0435 q \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e num function xsudoku(puzzle::AbstractMatrix{Int})     rows = Dict()     cols = Dict()     # \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438     for row in 1:9, col in 1:9, num in 1:9         r = []         quad = ((row-1)\u00f73)*3 + (col-1)\u00f73 + 1         push!(r, (0, row, col), (1, row, num), (2, col, num), (3, quad, num))         rows[(row, col, num)] = r     end     # \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b     for type in 0:3, n1 in 1:9, n2 in 1:9         cols[(type, n1, n2)] = Set()     end     for (rk, rv) in rows         for v in rv             push!(cols[v], rk)         end     end      # s - \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430     # \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0442\u0443\u0434\u0430 \u043d\u0430\u0434\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u0442\u0435 \u0446\u0438\u0444\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b     s = []     for i in 1:9, j in 1:9         if puzzle[i, j] &gt; 0             elt = (i, j, puzzle[i,j])             push!(s, elt)             # \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043a\u043b\u0435\u0442\u043a\u0443 \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u0441\u0435 \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b             extract_intersects!(rows, cols, elt)         end     end      # \u0432\u0441\u0451, \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c - \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435     success = algorithm_x(rows, cols, s)     success != nothing || return nothing     # \u043e\u0442\u0432\u0435\u0442 \u0432\u044b\u0434\u0430\u0434\u0438\u043c \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b     ret = similar(puzzle)     for (i, j, num) in s         ret[i,j] = num     end     return ret end<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"julia\"> julia&gt; @time xsudoku([0 0 0 0 0 0 4 0 0;        3 0 6 0 0 0 0 0 0;        0 0 0 1 9 6 0 3 0;        0 7 0 0 0 0 0 1 0;        8 0 0 2 5 0 0 9 0;        0 4 0 0 0 0 8 0 0;        0 6 0 4 0 9 0 0 8;        0 0 5 0 0 0 0 2 0;        0 0 0 5 0 0 0 0 7])   0.006326 seconds (54.91 k allocations: 3.321 MiB) 9\u00d79 Array{Int64,2}:  1  5  7  8  3  2  4  6  9  3  9  6  7  4  5  2  8  1  2  8  4  1  9  6  7  3  5  6  7  2  9  8  4  5  1  3  8  3  1  2  5  7  6  9  4  5  4  9  6  1  3  8  7  2  7  6  3  4  2  9  1  5  8  4  1  5  3  7  8  9  2  6  9  2  8  5  6  1  3  4  7<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u0430\u044f.<br \/>  \u041d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u0438\u0451\u043c\u043e\u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0441\u0443\u0434\u043e\u043a\u0443 (\u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/habr.com\/ru\/post\/173795\/\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/113837\/\">\u0437\u0434\u0435\u0441\u044c<\/a>) \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0435 \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b\u043e\u0441\u044c, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438 \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/462411\/\"> https:\/\/habr.com\/ru\/post\/462411\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c &#171;\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c X&#187; \u041a\u043d\u0443\u0442\u0430 \u0438 \u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u0443\u0434\u043e\u043a\u0443. \u041f\u0440\u0435\u043b\u0435\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0443\u0434\u043e\u043a\u0443 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u043e \u0431\u0435\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u0442\u0435\u0445\u043d\u0438\u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-292957","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292957"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292957\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}