Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table

http://codeforces.com/problemset/problem/509/A

题意:
输入n*n,除了第一行为1,后面都满足
res[i][j] = res[i - 1][j] + res[i][j - 1];
求二维数组中的最大值。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL res[12][12] = {0};
// 因为n不能大于10。建立二维数组,并初始化。
LL ans = 0;

int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == 1 || j == 1) { res[i][j] = 1; }
// 第一行,和每一列的第一个都为1.
else { res[i][j] = res[i - 1][j] + res[i][j - 1]; }
// 按照要求赋值。
ans = max(ans, res[i][j]);
// 虽然最大的是最右下角的值,但是这样保证程序的万无一失
}
}
cout << ans << endl;
return 0;
};