您的位置:首页 > 其它

BZOJ4300 绝世好题

2015-10-30 20:48 302 查看
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=4300

分析:DP.一开始想错了:以为认定一位,有最多数的就是答案,后来发现不一定子序列所有数都具有这一位,因为只是bi与bi-1关系。。。于是开始了正解之旅。。

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int Tmax2=40;
int n,f[Tmax2],ans;
bool v[Tmax2];
int main()
{
int i,a,j,top;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a);
j=-1;
memset(v,0,sizeof(v));
while(a>0)
{
v[++j]=(a&1);
a>>=1;
}
top=0;
for(j=0;j<=35;j++)
if(v[j])
top=max(top,f[j]+1);
for(j=0;j<=35;j++)
if(v[j])
f[j]=max(f[j],top);
}
for(i=0;i<=35;i++)
ans=max(ans,f[i]);
printf("%d\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: