이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
///Dynamic Programming
///Determine the maximum amount of coal
int n;
int food[100005];
int memo[100005][4][4][4][4];
int different(int a, int b, int c) ///Returns the quantity of different types of food
{
if (a > b) swap(a, b);
if (b > c) swap(b, c);
if (a > b) swap(a, b);
int cnt = 1;
if (a != b) {
cnt++;
}
if (b != c) {
cnt++;
}
if (a == 0) cnt--; // a = 0 means no food
return cnt;
}
///State: actual index of food, two last from mine 1, two last from mine 2
int coal(int i, int X1, int X2, int Y1, int Y2)
{
if (i == n) return 0;
if (memo[i][X1][X2][Y1][Y2] == -1) {
int maximum = max(coal(i + 1, food[i], X1, Y1, Y2)
+ different(food[i], X1, X2), ///Send food to mine 1
coal(i + 1, X1, X2, food[i], Y1)
+ different(food[i], Y1, Y2)); ///Send food to mine 2
memo[i][X1][X2][Y1][Y2] = maximum;
}
return memo[i][X1][X2][Y1][Y2];
}
int main()
{
memset(memo, -1, sizeof(memo));
cin >> n;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c == 'M')
food[i] = 1;
else if (c == 'F')
food[i] = 2;
else if (c == 'B')
food[i] = 3;
}
int maximum = coal(0, 0, 0, 0, 0);
cout << maximum << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |