“今日头条杯”首届湖北省大学程序设计竞赛--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();
}

 

转载于:https://www.cnblogs.com/fantastic123/p/8981229.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值