1646.cpp (419B)
1 class Solution { 2 public: 3 int getMaximumGenerated(int n) { 4 if (n == 0) return 0; 5 if (n == 1) return 1; 6 vector<int> vec(n + 1); 7 vec[0] = 0; 8 vec[1] = 1; 9 10 int maxi = 0; 11 for (int i = 2; i <= n; i++) { 12 vec[i] = vec[i / 2]; 13 if (i % 2) vec[i] += vec[i / 2 + 1]; 14 maxi = max(vec[i], maxi); 15 } 16 17 return maxi; 18 } 19 };