洛谷P4310 绝世好题(二进制优化、dp)

https://www.luogu.com.cn/problem/P4310

int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n; cin >> n; int res = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = 1; for (int j = 1; j < i; j++) { if (a[i] & a[j]) { dp[i] = max(dp[i], dp[j] + 1); if (dp[i] > res) { res = dp[i]; } } } } cout << res << endl; return 0; }
dp循环优化过版本还是90,TLE一个点。看题解才想起来超时点还可以是位运算,……别天天盯着那破循环优化了我服了

posted @ 2025-07-15 22:16  yubai111  阅读(8)  评论(0)    收藏  举报