代码实现:
方法一:递归——超时
#define min(a, b) ((a) > (b) ? (b) : (a)) int minDays(int n) { if (n == 1 || n == 2) { return n; } if (n % 3 == 0) { if (n % 2 == 0) { return min(min(minDays(n - 1), minDays(n / 2)), minDays(n - 2 * (n / 3))) + 1; } else { return min(minDays(n - 1), minDays(n - 2 * (n /3))) + 1; } } else { if (n % 2 == 0) { return min(minDays(n - 1), minDays(n / 2)) + 1; } else { return minDays(n - 1) + 1; } } }