zoukankan      html  css  js  c++  java
  • 洛谷P2380 狗哥采矿

    题目背景

    又是一节平静的语文课

    狗哥闲来无事,出来了这么一道题

    题目描述

    一个n*m的矩阵中,每个格子内有两种矿yeyenum和bloggium,并且知道它们在每个格子内的数量是多少。最北边有bloggium的收集站,最西边有 yeyenum 的收集站。现在要你在这些格子上面安装向北或者向西的传送带(每个格子只能装一种)。问最多能采到多少矿?

    输入输出格式

    输入格式:

    第一行包含两个整数n,m,( 1 ≤ n ≤ 500, 1 ≤ m ≤ 500)。接下来n行m列,表示每个格子中可以传送到yeyenum的数量(小于1000),再接下来n行m列,表示每个格子中可以传送到bloggium的数量。n, m 同时为0结束。

    输出格式:

    每组测试数据仅输出一个数,表示最多能采到的矿。

    输入输出样例

    输入样例#1: 复制
    4 4
    0 0 10 9 
    1 3 10 0
    4 2 1 3 
    1 1 20 0 
    10 0 0 0 
    1 1 1 30 
    0 0 5 5 
    5 10 10 10 
    0 0
    输出样例#1: 复制
    98

    说明

    传输过程中不能转弯,只能走直路。

    分析

    注意说明里面的内容,读题目要仔细啊。

    代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int N=505;
    inline int read(){
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,m;
    int a[N][N],b[N][N],f[N][N];
    int main(){
        while(1){
            n=read();m=read();
            if(n==0&&m==0) break;
            for(int i=1;i<=n;++i)
            for(int j=1;j<=m;++j)
            a[i][j]=a[i][j-1]+read();
            for(int i=1;i<=n;++i)
            for(int j=1;j<=m;++j)
            b[i][j]=b[i-1][j]+read();
            memset(f,0,sizeof(f));
            for(int i=1;i<=n;++i)
            for(int j=1;j<=m;++j)
            f[i][j]=max(f[i-1][j]+a[i][j],f[i][j-1]+b[i][j]);
            printf("%d
    ",f[n][m]);
        }
        return 0;
    }
  • 相关阅读:
    PHP中关于字符串的连接
    好用的FireFox(FF)插件
    Scripted Operation
    Scripted device
    chgrp chown
    wait_for_devices
    mysql create user
    mysql
    create user mysql
    Inserting/Removing shutters and filters
  • 原文地址:https://www.cnblogs.com/huihao/p/7955877.html
Copyright © 2011-2022 走看看