# DP
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int n;
pair<int, int> node[101];
vector<int> v[102];
int ans;
int dp[101];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d %d", &node[i].first, &node[i].second);
v[node[i].first].push_back(i);
}
for (int i = 1; i <= n; i++)
{
if (v[i].empty() == true)
continue;
if (v[i + 1].empty() == true)
{
for (auto & j : v[i])
{
int tmp = dp[j] + node[j].second;
ans = max(ans,tmp);
}
continue;
}
for (auto & j : v[i])
{
for (auto & k : v[i + 1])
{
dp[k] = max(dp[k], dp[j] + node[j].second + (k - j)*(k - j));
ans = max(ans, dp[k]);
}
}
}
printf("%d", ans);
return 0;
}'IT > BOJ' 카테고리의 다른 글
| 백준(BOJ) 16174 점프왕 젤리 ** (0) | 2018.10.04 |
|---|---|
| 백준(BOJ) 16172 나는 친구가 적다 ** (0) | 2018.10.04 |
| 백준(BOJ) 16168 퍼레이드 ** (0) | 2018.10.04 |
| 백준(BOJ) 16167 A Great Way * (0) | 2018.10.04 |
| 백준(BOJ) 16166 서울의 지하철 * (0) | 2018.10.04 |