zoukankan      html  css  js  c++  java
  • uva-10827

      题意:还是寻找子数组和最大,只是上下左右可以联通了,NxN,变成2Nx2N就行了,循环了四层,D_Double用了三层,有个大佬用dp是俩层

    #include <string>
    #include<iostream>
    #include<map>
    #include<memory.h>
    #include<vector>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<math.h>
    #include<iomanip>
    #include<bitset>
    #include"math.h"
    namespace cc
    {
        using std::cout;
        using std::endl;
        using std::cin;
        using std::map;
        using std::vector;
        using std::string;
        using std::sort;
        using std::priority_queue;
        using std::greater;
        using std::vector;
        using std::swap;
        using std::stack;
        using std::queue;
        using std::bitset;
    
    
        constexpr int N = 80;
        int a[N * 2][N * 2]; 
    
        void solve()
        {
            int n;
            cin >> n;
            while (n--)
            {
                int R;
                cin >> R;
                memset(a, 0, sizeof(a));
                for (int i = 1;i <= R;i++)
                {
                    for (int j = 1;j <= R;j++)
                    {
                        cin >> a[i][j];
                        a[i][R + j] = a[i][j];
                        a[R + i][j] = a[i][j];
                        a[R + i][R + j] = a[i][R + j];
                    }
                }
                for (int i = 1;i <= 2*R;i++)
                {
                    for (int j = 1;j <= 2*R;j++)
                    {
                        a[i][j] = a[i][j] + a[i - 1][j];
                    }
    
                }
                int max = INT32_MIN;
                for (int i = 0;i <= R;i++)
                {
                    for (int j = i + 1;j <= i + R;j++)
                    {
                        for (int k = 1;k <= R;k++)
                        {
                            int sum = 0;
                            for (int c = k;c < k + R;c++)
                            {
                                if (sum < 0)
                                    sum = 0;
                                else
                                    sum = sum + a[j][c] - a[i][c];
                                if (sum > max) 
                                {
                                    max = sum;
                                }
                            }
                        }
                    }
                }
                cout << max << endl;
    
    
            }
    
    
        }
    };
     
    
    int main()
    {
    
    #ifndef ONLINE_JUDGE
        freopen("d://1.text", "r", stdin);
    #endif // !ONLINE_JUDGE
        cc::solve();
    
    
    
        return 0;
    }
  • 相关阅读:
    drf 反序列化
    drf学习 第一天 序列化器
    flex学习之作用在items上的属性
    flex学习之align-content
    flex学习之flex-wrap
    flex学习之align-itmes
    flex弹性盒子中jstify-content
    将主机变为服务器,ssh连接出现access denied
    为什么用tensor不用array?
    深度学习之Epoch、Batch、Iteration
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/10810150.html
Copyright © 2011-2022 走看看