-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3144f46
commit cb6d6a0
Showing
8 changed files
with
219 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("NEW_maximumSum_UVA108.in"); | ||
ofstream fout("NEW_maximumSum_UVA108.out"); | ||
|
||
const int minf = -128; | ||
|
||
int main() | ||
{ | ||
while (true) | ||
{ | ||
int n = 0; fin >> n; | ||
if (n == 0) break; | ||
|
||
vector<vector<int>> a(n + 1, vector<int>(n + 1, minf)); | ||
for (int y = 1; y <= n; ++y) | ||
{ | ||
for (int x = 1; x <= n; ++x) | ||
{ | ||
fin >> a[y][x]; | ||
} | ||
} | ||
|
||
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0)); | ||
for (int x = 1; x <= n; ++x) | ||
{ | ||
for (int y = 1; y <= n; ++y) | ||
{ | ||
dp[x][y] = dp[x][y - 1] + a[y][x]; | ||
} | ||
} | ||
|
||
int ans = minf; | ||
for (int y1 = 1; y1 <= n; ++y1) | ||
{ | ||
for (int y2 = y1; y2 <= n; ++y2) | ||
{ | ||
int last = 0; | ||
for (int x = 1; x <= n; ++x) | ||
{ | ||
int now = dp[x][y2] - dp[x][y1 - 1]; | ||
|
||
last = max(now, last + now); | ||
ans = max(ans, last); | ||
} | ||
} | ||
} | ||
|
||
fout << ans << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
4 | ||
-1 -2 -3 -4 | ||
-5 -6 -7 -8 | ||
-9 -10 -11 -12 | ||
-13 -14 -15 -16 | ||
5 | ||
1 -61 5126 612 6 | ||
41 6 7 2 -7 | ||
1 73 -62 678 1 | ||
7 -616136 61 -83 724 | ||
-151 6247 872 2517 8135 | ||
4 | ||
0 -2 -7 0 | ||
9 2 -6 2 | ||
-4 1 -4 1 | ||
-1 8 0 -2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-1 | ||
18589 | ||
15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
const int minf = -128; | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
while (true) | ||
{ | ||
int n = 0; cin >> n; | ||
if (n == 0) break; | ||
|
||
vector<vector<int>> a(n + 1, vector<int>(n + 1, minf)); | ||
for (int y = 1; y <= n; ++y) | ||
{ | ||
for (int x = 1; x <= n; ++x) | ||
{ | ||
cin >> a[y][x]; | ||
} | ||
} | ||
|
||
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0)); | ||
for (int x = 1; x <= n; ++x) | ||
{ | ||
for (int y = 1; y <= n; ++y) | ||
{ | ||
dp[x][y] = dp[x][y - 1] + a[y][x]; | ||
} | ||
} | ||
|
||
int ans = minf; | ||
for (int y1 = 1; y1 <= n; ++y1) | ||
{ | ||
for (int y2 = y1; y2 <= n; ++y2) | ||
{ | ||
int last = 0; | ||
for (int x = 1; x <= n; ++x) | ||
{ | ||
int now = dp[x][y2] - dp[x][y1 - 1]; | ||
|
||
last = max(now, last + now); | ||
ans = max(ans, last); | ||
} | ||
} | ||
} | ||
|
||
cout << ans << '\n'; | ||
} | ||
|
||
cout.flush(); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +0,0 @@ | ||
#include <algorithm> | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <fstream> | ||
#include <climits> | ||
#include <functional> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("maximumSum.in"); | ||
ofstream fout("maximumSum.out"); | ||
|
||
int main() | ||
{ | ||
while (true) | ||
{ | ||
int n = - 1; | ||
fin >> n; | ||
|
||
if (n == -1) | ||
{ | ||
break; | ||
} | ||
|
||
vector<vector<int>> a(n, vector<int>(n)); | ||
vector<vector<int>> dp(n, vector<int>(n + 1)); | ||
for (int y = 0; y <= n - 1; ++y) | ||
{ | ||
int sum = 0; | ||
dp[y][0] = 0; | ||
for (int x = 0; x <= n - 1; ++x) | ||
{ | ||
fin >> a[y][x]; | ||
sum += a[y][x]; | ||
dp[y][x + 1] = sum; | ||
} | ||
} | ||
|
||
int maxSum = INT_MIN; | ||
for (int y0 = 0; y0 <= n - 1; ++y0) | ||
{ | ||
for (int x0 = 0; x0 <= n - 1; ++x0) | ||
{ | ||
for (int x1 = x0 + 1; x1 <= n; ++x1) | ||
{ | ||
int sum = 0; | ||
for (int y1 = y0; y1 <= n - 1; ++y1) | ||
{ | ||
sum += dp[y1][x1] - dp[y1][x0]; | ||
maxSum = max(maxSum, sum); | ||
} | ||
} | ||
} | ||
} | ||
|
||
fout << maxSum << '\n'; | ||
} | ||
|
||
return 0; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <algorithm> | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <fstream> | ||
#include <climits> | ||
#include <functional> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("maximumSum.in"); | ||
ofstream fout("maximumSum.out"); | ||
|
||
int main() | ||
{ | ||
while (true) | ||
{ | ||
int n = - 1; | ||
fin >> n; | ||
|
||
if (n == -1) | ||
{ | ||
break; | ||
} | ||
|
||
vector<vector<int>> a(n, vector<int>(n)); | ||
vector<vector<int>> dp(n, vector<int>(n + 1)); | ||
for (int y = 0; y <= n - 1; ++y) | ||
{ | ||
int sum = 0; | ||
dp[y][0] = 0; | ||
for (int x = 0; x <= n - 1; ++x) | ||
{ | ||
fin >> a[y][x]; | ||
sum += a[y][x]; | ||
dp[y][x + 1] = sum; | ||
} | ||
} | ||
|
||
int maxSum = INT_MIN; | ||
for (int y0 = 0; y0 <= n - 1; ++y0) | ||
{ | ||
for (int x0 = 0; x0 <= n - 1; ++x0) | ||
{ | ||
for (int x1 = x0 + 1; x1 <= n; ++x1) | ||
{ | ||
int sum = 0; | ||
for (int y1 = y0; y1 <= n - 1; ++y1) | ||
{ | ||
sum += dp[y1][x1] - dp[y1][x0]; | ||
maxSum = max(maxSum, sum); | ||
} | ||
} | ||
} | ||
} | ||
|
||
fout << maxSum << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
//ifstream fin("lineSwap.in"); | ||
//ofstream fout("lineSwap.out"); | ||
|
||
class line | ||
{ | ||
double y_start; | ||
double y_end; | ||
double x; | ||
int flag; | ||
}; | ||
|
||
int main() | ||
{ | ||
|
||
|
||
return 0; | ||
} |