zoukankan      html  css  js  c++  java
  • codeforce#483div2D-XOR-pyramid+DP

    题意:求给定区间中最大的连续异或和;

    思路:DP的思想,先dp求出每个区间的异或和,再dp更新成当前这个dp[i][j]和dp[i-1][j]、dp[i-1][j+1]中的最大值;

       这样可以保证是同一个区间亦或。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <queue>
    #include <list>
    #include <iterator>
    #include <cmath>
    using namespace std;
    
    typedef long long ll;
    
    const int maxn = 5009;
    int n;
    ll p,q,b;
    ll dp[maxn][maxn];
    
    int main(){
           scanf("%d", &n);
           for(int i=1; i<=n; i++)
           {
               scanf("%lld", &dp[1][i]);
           }
           for(int i=2; i<=n; ++i)
           {
               for(int j=1; j<=n-i+1; ++j)
               {
                   dp[i][j] = dp[i-1][j]^dp[i-1][j+1];
               }
           }
      
           for(int i=2; i<=n; i++)
           {
               for(int j=1; j<=n-i+1;j++)
               {
                   dp[i][j] = max(dp[i][j],max(dp[i-1][j],dp[i-1][j+1]));
               }
           }
    
           int q;
           scanf("%d", &q);
           for(int i=1; i<=q; i++)
           {
               int x,y;
               scanf("%d%d", &x,&y);
               printf("%lld
    ",dp[y-x+1][x]);
           }
        return 0;
    }
  • 相关阅读:
    Ionic开发手机App常用的软件
    Windows的Ionic环境配置
    百度静态资源公共库
    我的程序员之路
    angular.bind
    响应式布局之使用bootstrap
    初识bootstrap
    使用css3实现响应式布局
    mysql-阅读笔记1
    mysql优化
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/9046513.html
Copyright © 2011-2022 走看看