From 546ebc169fd53800bb8266967b44755f65f4ba82 Mon Sep 17 00:00:00 2001 From: Familia Date: Tue, 22 Jul 2008 23:16:30 -0500 Subject: [PATCH] =?utf8?q?836=20-=20Largest=20submatrix=20(DP,=20programac?= =?utf8?q?i=C3=B3n=20din=C3=A1mica,=20O(n^4)=20=C2=BFExistir=C3=A1=20un=20?= =?utf8?q?O(n^3)=3F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- 836 - Largest submatrix/836 | Bin 0 -> 22971 bytes 836 - Largest submatrix/836.cpp | 48 +++++++++++++++++++++++++++ 836 - Largest submatrix/in.txt | 71 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100755 836 - Largest submatrix/836 create mode 100644 836 - Largest submatrix/836.cpp create mode 100644 836 - Largest submatrix/in.txt diff --git a/836 - Largest submatrix/836 b/836 - Largest submatrix/836 new file mode 100755 index 0000000000000000000000000000000000000000..2b4a697173fb7b7701e0d5c279bcbcec32990978 GIT binary patch literal 22971 zcwW7H4SbZvwf8)m-DH740>p|+HE2Lk2>BuetO~+|Mm~%rv8d38WwT@#H@oTXh7Ye; zxJhnVm$g>Gs#kr*V#{l7rCzQtw%CS`0`}6H+tQZyrQWm`@7);Gh*2U$^Pd0AJRiH+ z5as%N7bf%kXU@!=IcMg~c|K;or7l{aC<@bmHkQGFs^WHM8O1F#M0y#^XHGVmO=8!u zOpYmRA{q+300jp{b_yBDBV4wb@+piZJXYpOQt?As3bj)iLqK_!EAp2SUbfHfMA%6Q zCvA+ki+s9djg;R=c?b!@2$`}CgxjdhZPYeGKH+>zUe()?x?K|)+x3FoiEx_IPFwQt zqE6wE~9V>Gxa}K#$QQ8JH~R2KI?6x-`}NHCalcMKpOgv zK7}67vSq!tCh*e2|7@G^Y0t2{C$i^lsJ!ph)Ovp?7GDG06 zOT5D-@FfygNxW2Iz5n>-GgB8jenwu;mh``r?OiMJtulY6#JaFnN<2&EkCb?u%zr*h z;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NtdlP?CT7u?AaQFo zjr!0Ch77|ngSZMdZlE&m`_{Qab(M=&6{%za%0p!6f(@F>?e>Jj#t_jWu6ngxl;9Js zl;#aisev*`B`GsoP91X`ijkxZJS)VUH2esag%@QK%FuJm`7=0iB~?-wR+_Nj!3|gi zP#HHR#TtoFTkZ0PJz8W#qi2wDOvSC=_o+k8DJn>V)I6{!%_%b}JfLxUa}f~&kzO) z6R6H(NQKy2V_hbN6E(CA7-X?BjR4J?foA-oL{+C-m4SJ)8k@piZa&pClk4+0(b%Xv zUu1-u0*2S=sS^g;b=^5TRBHCUA(&44&C?TcCT;-UeQ z$2g=c&1yF*Wrf$*Jo3~eLnRv5X4>IhE>^lPxXMwp6$8icmnS-!C1vSn3H9yEX(iPc z;J0ciC%~og!Uj| +#include + +using namespace std; + +int main(){ + int C; + cin >> C; + string line; + getline(cin, line); + getline(cin, line); + for (int c=0; c 0) cout << endl; + vector m; + while (getline(cin, line) && line != ""){ + m.push_back("0" + line); + } + int n = m.size(); + m.insert(m.begin(), string(n+1, '0')); + + /* + dp[i][j] = suma de la matriz que va desde la esquina (0,0) hasta la esquina (i,j) + */ + int dp[n+1][n+1]; + for (int i=0; i<=n; ++i) + for (int j=0; j<=n; ++j) + dp[i][j] = m[i][j] - '0'; + + for (int i=1; i<=n; ++i) + for (int j=1; j<=n; ++j) + dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]; + + int answer = 0; + for (int i=1; i<=n; ++i) + for (int j=1; j<=n; ++j) + for (int a=i; a<=n; ++a) + for (int b=j; b<=n; ++b){ + if ( ( dp[a][b] - dp[a][j-1] - dp[i-1][b] + dp[i-1][j-1] ) == (a - i + 1)*(b - j + 1) ){ + answer = max(answer, (a-i+1)*(b-j+1)); + } + } + + cout << answer << endl; + + + } + return 0; +} diff --git a/836 - Largest submatrix/in.txt b/836 - Largest submatrix/in.txt new file mode 100644 index 0000000..7a651ce --- /dev/null +++ b/836 - Largest submatrix/in.txt @@ -0,0 +1,71 @@ +4 + +10111000 +00010100 +00111000 +00111010 +00111111 +01011110 +01011110 +00011110 + +10111000 +00010100 +00111000 +00111010 +00111111 +01011010 +01011110 +00011110 + +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 + +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111110111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 +1111111111111111111111111 -- 2.11.4.GIT