zoukankan      html  css  js  c++  java
  • NC112798 XOR-pyramid(dp)

    观察式子信息,就能发现原始序列的答案为f[i+1][j]^f[i][j-1]而来

    因此维护一下区间最大值之后O(1)输出即可

    #include<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    typedef pair<int,int> pll;
    const int N=1e6+10;
    const int inf=0x3f3f3f3f;
    const int mod=1e9+7;
    int n;
    ll res[5050][5050];
    ll f[5050][5050];
    int main(){
        ios::sync_with_stdio(false);
        cin>>n;
        int i;
        for(i=1;i<=n;i++){
            cin>>f[i][i];
            res[i][i]=f[i][i];
        }
        for(int len=2;len<=n;len++){
            for(i=1;i+len-1<=n;i++){
                int j=i+len-1;
                f[i][j]=f[i+1][j]^f[i][j-1];
                res[i][j]=max(res[i][j-1],f[i][j]);
                res[i][j]=max(res[i][j],res[i+1][j]);
            }
        }
        int q;
        cin>>q;
        while(q--){
            int l,r;
            cin>>l>>r;
            cout<<res[l][r]<<endl;
        }
        return 0;
    }
    View Code
    没有人不辛苦,只有人不喊疼
  • 相关阅读:
    git
    *** errRun
    Centos与Debian的安装命令
    HTML基础
    基本的SQL语言
    phpstudy靶场搭建
    Centos7下搭建服务器(apache+mysql+php)
    Centos7设置yum源
    Linux基础
    一个服务器中搭建多个站点
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/14535899.html
Copyright © 2011-2022 走看看