“今日头条杯”首届湖北省大学程序设计竞赛--F. Flower Road

题目链接:点这

github链接:(包含数据和代码,题解):点这

链接:https://www.nowcoder.com/acm/contest/104/E
来源:牛客网

题目描述

(受限于评测机,此题数据范围与现场赛不一致,请谅解)

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)).

输入描述:

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 the max sum of the satisfaction.
示例1

输入

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

输出

81

意思就是:给你个矩阵,中间有m个操作,选择矩阵,本来以为会卡时间,但是好想并没有,直接旋转,然后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;
        }
    }
}
int main()
{
    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();
}

猜你喜欢

转载自www.cnblogs.com/fantastic123/p/8981229.html
今日推荐