• 51Nod 1083 矩阵取数问题


    一个N*N矩阵中有不同的正整数,经过这个格子,就能获得相应价值的奖励,从左上走到右下,只能向下向右走,求能够获得的最大价值。
     
    例如:3 * 3的方格。
     
    1 3 3
    2 1 3
    2 2 1
     
    能够获得的最大价值为:11。
    Input
    第1行:N,N为矩阵的大小。(2 <= N <= 500)
    第2 - N + 1行:每行N个数,中间用空格隔开,对应格子中奖励的价值。(1 <= N[i] <= 10000)
    Output
    输出能够获得的最大价值。
    Input示例
    3
    1 3 3
    2 1 3
    2 2 1
    Output示例
    11
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 using namespace std;
    13 #define lowbit(x) (x&(-x))
    14 #define max(x,y) (x>y?x:y)
    15 #define min(x,y) (x<y?x:y)
    16 #define MAX 100000000000000000
    17 #define MOD 1000000007
    18 #define pi acos(-1.0)
    19 #define ei exp(1)
    20 #define PI 3.141592653589793238462
    21 #define INF 0x3f3f3f3f3f
    22 #define mem(a) (memset(a,0,sizeof(a)))
    23 typedef long long ll;
    24 const int N=10005;
    25 const int mod=1e9+7;
    26 int a[501][501];
    27 
    28 int main()
    29 {
    30     int n;
    31     cin>>n;
    32     mem(a);
    33     for(int i=1;i<=n;i++){
    34         for(int j=1;j<=n;j++){
    35             cin>>a[i][j];
    36         }
    37     }
    38     for(int i=1;i<=n;i++){
    39         for(int j=1;j<=n;j++){
    40             if(i==1&&j==1) continue;
    41             else {
    42                 a[i][j]=max(a[i-1][j],a[i][j-1])+a[i][j];
    43             }
    44         }
    45     }
    46     sort(a[n],a[n]+n+1);
    47     cout<<a[n][n]<<endl;
    48     return 0;
    49 }
  • 相关阅读:
    python中的对象
    在python中是没有NULL的,取而代之的是None,它的含义是为空
    Python将列表作为栈和队列
    Python的数据类型3元组,集合和字典
    1
    Python的数据类型2列表
    _Python定义方法
    IDEA
    Docker-compose.yml 基础使用
    Nginx 前后端分离, 多个二级域名配置
  • 原文地址:https://www.cnblogs.com/wydxry/p/7256626.html
Copyright © 2020-2023  润新知