Skip to content

Instantly share code, notes, and snippets.

@k3kys
Last active May 2, 2021 01:40
Show Gist options
  • Save k3kys/18d23cb1433f3bbfb82db99e1205b557 to your computer and use it in GitHub Desktop.
Save k3kys/18d23cb1433f3bbfb82db99e1205b557 to your computer and use it in GitHub Desktop.
12869
#include <bits/stdc++.h>
using namespace std;
int d[61][61][61];
int go(int i, int j, int k) {
if (i < 0) return go(0, j, k);
if (j < 0) return go(i, 0, k);
if (k < 0) return go(i, j, 0);
if (i == 0 && j == 0 && k == 0) return 0;
int &ans = d[i][j][k];
if (ans != -1) return ans;
ans = 10000000;
vector<int> p = { 1, 3, 9 };
do {
if (ans > go(i - p[0], j - p[1], k - p[2])) {
ans = go(i - p[0], j - p[1], k - p[2]);
}
} while (next_permutation(p.begin(), p.end()));
ans += 1;
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n;
cin >> n;
int scv[3] = { 0, 0, 0 };
for (int i = 0; i < n; i++) cin >> scv[i];
memset(d, -1, sizeof(d));
cout << go(scv[0], scv[1], scv[2]) << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment