(ΦωΦ)<これの答えですよー。目次はここ。
---
問2-6
#include <iostream>
#include <algorithm>
using namespace std;
class MutaliskEasy { public: int minimalAttacks(vector<int> x); };
const int inf = 987654321;
vector<vector<vector<int>>> dp;
int f(int x, int y) { return max(0, x-y); }
int MutaliskEasy::
minimalAttacks(vector<int> a) {
int n = a.size();
for(int i=n; i<3; i++) { a.push_back(0); }
dp.assign(70, vector<vector<int>>(70, vector<int>(70)));
for(int i=0; i<65; i++) {
for(int j=0; j<65; j++) {
for(int k=0; k<65; k++) {
if(i==0 && j==0 && k==0) { dp[i][j][k] = 0; continue; }
vector<int> v = {1, 3, 9};
int res = inf;
do {
res = min(res, dp[f(i,v[0])][f(j,v[1])][f(k,v[2])] + 1);
} while(next_permutation(v.begin(), v.end()));
dp[i][j][k] = res;
}
}
}
return dp[a[0]][a[1]][a[2]];
}
(ΦωΦ)<おしまい