0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 21:08:47 +00:00

P1216 [USACO1.5][IOI1994]数字三角形 Number Triangles

R65907168
This commit is contained in:
Baoshuo Ren 2021-12-27 21:19:36 +08:00
parent 88b60390ec
commit fcadb28e33
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -1,24 +1,29 @@
#include <bits/stdc++.h> #include <iostream>
#include <limits>
using namespace std; using std::cin;
using std::cout;
using std::endl;
const int N = 1005;
int r, g[N][N], f[N][N], ans = std::numeric_limits<int>::min();
int main() { int main() {
int n, a[1005][1005], f[1005][1005]; cin >> r;
cin >> n; for (int i = 1; i <= r; i++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) { for (int j = 1; j <= i; j++) {
cin >> a[i][j]; cin >> g[i][j];
} }
} }
f[1][1] = a[1][1]; f[1][1] = g[1][1];
for (int i = 1; i <= n; i++) { for (int i = 1; i <= r; i++) {
for (int j = 1; j <= i + 1; j++) { for (int j = 1; j <= i + 1; j++) {
f[i][j] = a[i][j] + max(f[i - 1][j], f[i - 1][j - 1]); f[i][j] = std::max(f[i - 1][j - 1], f[i - 1][j]) + g[i][j];
} }
} }
int ans = -0x3f3f3f; for (int i = 1; i <= r; i++) {
for (int i = 1; i <= n; i++) { ans = std::max(ans, f[r][i]);
ans = max(ans, f[n][i]);
} }
cout << ans << endl; cout << ans << endl;
return 0; return 0;