mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 14:58:48 +00:00
P1216 [USACO1.5][IOI1994]数字三角形 Number Triangles
R65907168
This commit is contained in:
parent
88b60390ec
commit
fcadb28e33
@ -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 n, a[1005][1005], f[1005][1005];
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> r;
|
||||
for (int i = 1; i <= r; i++) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
cin >> a[i][j];
|
||||
cin >> g[i][j];
|
||||
}
|
||||
}
|
||||
f[1][1] = a[1][1];
|
||||
for (int i = 1; i <= n; i++) {
|
||||
f[1][1] = g[1][1];
|
||||
for (int i = 1; i <= r; i++) {
|
||||
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 <= n; i++) {
|
||||
ans = max(ans, f[n][i]);
|
||||
for (int i = 1; i <= r; i++) {
|
||||
ans = std::max(ans, f[r][i]);
|
||||
}
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user