bzoj 4300: 绝世好题 dp

4300: 绝世好题

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=4300

Description

给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len)。

Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won’t get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

⋅2. Ignoring the buoys and relying on dogfighting to get point. If you and your opponent meet in the same position, you can try to fight with your opponent to score one point. For the proposal of game balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder: As a player specializing in high speed movement, he/she tries to avoid dogfighting while attempting to gain points by touching buoys.
Fighter: As a player specializing in dogfighting, he/she always tries to fight with the opponent to score points. Since a fighter is slower than a speeder, it’s difficult for him/her to score points by touching buoys when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting. Since Asuka is slower than Shion, she decides to fight with Shion for only one time during the match. It is also assumed that if Asuka and Shion touch the buoy in the same time, the point will be given to Asuka and Asuka could also fight with Shion at the buoy. We assume that in such scenario, the dogfighting must happen after the buoy is touched by Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

Input

输入文件共2行。 第一行包括一个整数n。 第二行包括n个整数,第i个整数表示ai。

 

Output

输出文件共一行。 包括一个整数,表示子序列bi的最长长度。

 

Sample Input

3
1 2 3

Sample Output

2

HINT

 

题意

 

题解:

直接dp就好了,dp[i]表示第i位为1的时候,最长多长

代码

 

#include<iostream>
#include<stdio.h>
using namespace std;

int dp[34];
int main()
{
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;scanf("%d",&x);
        int tmp = 0;
        for(int j=0;j<=30;j++)
            if(x&(1<<j))
                tmp=max(dp[j]+1,tmp);
        for(int j=0;j<=30;j++)
            if(x&(1<<j))
                dp[j]=max(dp[j],tmp);
    }
    int ans = 0;
    for(int i=0;i<=30;i++)
        ans = max(ans,dp[i]);
    printf("%d\n",ans);
}

 

    原文作者:qscqesze
    原文地址: https://www.cnblogs.com/qscqesze/p/4936475.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞