zoukankan      html  css  js  c++  java
  • codeforces#983 B. XOR-pyramid (dp)

    参考博客:https://www.01hai.com/note/av137952、

    题意:首先定义

    (b代表一个数组)

    给出一个区间,l,r,求它最大的连续子序列的函数值

    分析:

    定义dp[x][y]为选取x到y这段区间时的函数值

    观察发现dp[x][y]=dp[x+1][y]^dp[x][y-1]

    代码:

    #include<bits/stdc++.h>
    #define ll long long
    #define  pa pair<int,int>
    using namespace std;
    const int maxn=5e3+10;
    int n,dp[maxn][maxn];
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&dp[i][i]);
        for(int i=2;i<=n;i++)
        {
            for(int l=1;l+i-1<=n;l++)
            {
                int r=l+i-1;
                dp[l][r]=dp[l+1][r]^dp[l][r-1];
            }
        }
        for(int i=2;i<=n;i++)
        {
            for(int l=1;l+i-1<=n;l++)
            {
                int r=l+i-1;
                dp[l][r]=max(dp[l][r],max(dp[l+1][r],dp[l][r-1]));
            }
        }
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int a,b;
            scanf("%d %d",&a,&b);
            printf("%d
    ",dp[a][b]);
        }
        return 0;
    }
    

      

  • 相关阅读:
    jquery operate
    ujs
    图标站
    rails foreign key
    feedback product from uservoice
    秒杀网
    short url
    rails nil blank
    paperclip imagemagic api &paperclip relevent
    类似优米网
  • 原文地址:https://www.cnblogs.com/carcar/p/10336462.html
Copyright © 2011-2022 走看看