Codeforces 1720D1 Xor-Subsequence (easy version)

Problem Link

The most apparant solution to this problem would be dynamic programming with O ( n 2 ) \mathcal O (n^2) O(n2) complexity, where each f i f_i fi would take O ( n ) \mathcal O(n) O(n) time to calculate.

The key to this problem is the domain of a i a_i ai, which is only 200 200 200. Since a ⊕ x ∈ [ a − x , a + x ] a \oplus x \in [a-x,a+x] ax[ax,a+x], only the indice in range i − 400 i-400 i400 would possibly contribute to the computation of f f f. Therefore, we can narrow down the complexity to O ( 400 n ) \mathcal O(400n) O(400n)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int Maxn=3e5+10;
const int Maxm=512;
int a[Maxn],f[Maxn];
int n;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	// freopen("in.txt","r",stdin);
	int T=read();
	while(T--)
	{
		n=read();
		for(int i=0;i<n;++i)
		a[i]=read();
		int ans=1;
		for(int i=0;i<n;++i)
		{
			f[i]=1;
			for(int j=max(0,i-512);j<i;++j)
			if(f[j]+1>f[i] && (a[j]^i)<(a[i]^j))f[i]=f[j]+1;
			ans=max(ans,f[i]);
		}
		printf("%d\n",ans);
		fill(f,f+1+n,0);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值