"Today's Toutiao Cup" The First Hubei University Programming Competition--F. Flower Road

Topic link: click here

github link: (including data and code, problem solving): click here

Link: https://www.nowcoder.com/acm/contest/104/E
Source: Niuke.com

Topic description

(Limited by the evaluation machine, the data range of this question is inconsistent with the live competition, please understand)

Once upon a time, there was a beautiful princess named TQM, and a handsome prince named GSS. One day, the prince would like to visit the princess. While in front of the princess' house, there was a flower-beds with blooming flowers. The prince was supposed to go through the flower-beds choosing the best ``Flower Road''.

Here is the task. The flower-beds is presented by a matrix with integers on each grid representing the princess' satisfaction of the flowers on it. Now, the prince was on the top left point (1, 1) and the princess was on the bottom right point (N, N). While the princess didn't want this to be so easy, she operated M times ``rotation'' on the flower-beds according to the order. Each time, she would choose a matrix whose top left point was . Then, four disjoint parts of the matrix whose length of size was rotated clockwise. Here is an example to make the ``rotation'' clearly.


Then, your task is to help the prince to choose a best ``Flower Road'' after these operations with the largest sum of the satisfaction. By the way, the prince will take the shortest way, which means he will only go down (from point (x, y) to point (x+1, y)) and right (from point (x, y) to point (x, y+1)).

Enter description:

The first line of input contains two integers, N (
) and M (
), indicating the numbers N and M described above. Then N lines follow, and each line N integers, representing the matrix. Then M lines follow, each line has three integers
, where x
i
and y
i
are coordinates of the top right point of i-th rotation matrix,
th - side length of the matrix.

Output description:

Output the max sum of the satisfaction.
Example 1

enter

4 1
1 2 5 6
3 4 7 8
13 14 9 10
15 16 11 12
1 1 2

output

81 

means: give you a matrix, there are m operations in the middle, select the matrix, I thought it would be time-stuck, but I really don’t think so, rotate directly, and then Dp

/*
    author:gsw
    data:2018.05.02
    link:https://www.nowcoder.com/acm/contest/104/E
    accout:tonygsw
*/
#define ll long long
#define IO ios::sync_with_stdio(false);
#define maxn 1505

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;

int n,m,x,y,l;
ll dp[maxn][maxn];
int value[maxn][maxn];

void init()
{
    memset(dp,0,sizeof(dp));
}

int DP()
{
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            dp[i][j]=max(dp[i][j],max(dp[i-1][j]+value[i][j],dp[i][j-1]+value[i][j]));
    printf("%lld\n",dp[n][n]);
}
inline void xz(int x,int y,int l)
{
    for(int i=0;i<l;i++)
    {
        for(int j=0;j<l;j++)
        {
            int tem=value[x+i][y+j];
            //cout<<tem<<" ---------"<<endl;
            value[x+i][y+j]=value[x+i+l][y+j];
            value[x+i+l][y+j]=value[x+i+l][y+j+l];
            value[x+i+l][y+j+l]=value[x+i][y+j+l];
            value[x+i][y+j+l]=tem;
        }
    }
}
intmain ()
{
    init();
    scanf("%d%d",&n,&m);
    //cout<<n<<" "<<m<<"-----------"<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            scanf("%d",&value[i][j]);
        }
    }
    //cout<<n<<" "<<m<<"-----------"<<endl;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d",&x,&y,&l);
        xz(x,y,l);
    }
/*
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        cout<<value[i][j]<<" ";
        cout<<endl;
    }*/
    DP();
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325131131&siteId=291194637