最后一个题我直接深度优先暴力求解也过了 ``` int dfs(const vector<vector<int>>& v, int left, int right) { if(left + 1 >= right) { return v[left][right]; } int mid = (left + right) >> 1; return v[dfs(v, left, mid - 1)][dfs(v, mid, right)]; } int main() { // freopen("C:\\Users\\Admin\\Desktop\\VScode\\c++\\file in.txt", "r", stdin); cin.tie(nullptr)->sync_with_stdio(false); int k = 0; cin >> k; int n = (int)pow(2, k); vector<int> a(n + 1, 0); vector<vector<int>> v(n + 1, vector<int>(n + 1, 1)); for(int i = 1; i <= n; i++) { a[i] = i; for(int j = 1; j <= n; j++) { cin >> v[i][j]; } } int ans = dfs(v, 1, n); cout << ans << endl; return 0; } ```
点赞 2

相关推荐

牛客网
牛客企业服务