hihoCoder太阁最新面经算法竞赛11 register

Ended

Participants:176

Verdict:Accepted
Score:100 / 100
Submitted:2016-10-16 20:28:12

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;
int f[201][201];
int fmin(int l, int r) {
    if(l >= r) return 0;
    if(f[l][r] > 0) return f[l][r];
    int res = INT_MAX;
    for(int i = l; i <= r; i++) {
        res = min(res, i + max(fmin(l, i - 1), fmin(i + 1, r)));
    }
    return f[l][r] = res;
}
int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", fmin(1, n));
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX