• SDNU 1038.收集宝藏(dp)


    Description

    有一个n*n的矩阵,矩阵每个格子中都有一些宝藏,从左上角(1, 1)出发,每次只能向下或者向右移动一格,已知每个格子中宝藏的价值,求走到右下角(n, n)时能收集到的宝藏的总最大价值。

    Input

    第一行为一个整数n(1 <= n <= 1000),表示矩阵的行、列数。
    接下来n行,每行n个整数,每个整数表示当前格子的宝藏价值(不超过10000)。

    Output

    一个整数,表示能收集到的宝藏的最大总价值。

    Sample Input

    4
    1 2 3 10
    3 4 1 1
    5 2 1 1
    1 3 1 1

    Sample Output

    19
    思路:这道题就是简单的dp,我个傻吊打了一百多行的bfs,结果还不对,真是像极了cxk。然后大佬告诉我这就是个超级无敌简单的dp,用简单的dp就过了。嘤嘤嘤...
    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <map>
    using namespace std;
    
    int n, fig[1000+8][1000+8], v, dp[1000+8][1000+8];
    
    int main()
    {
        memset(dp, 0, sizeof(dp));
        scanf("%d", &n);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                scanf("%d", &fig[i][j]);
        for(int i = 1; i<=n; i++)
            for(int j = 1; j<=n; j++)
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])+fig[i][j];
        printf("%d
    ", dp[n][n]);
        return 0;
    }
  • 相关阅读:
    windows下面安装Python和pip教程
    Python已安装第三方库
    Python安装cx_Oracle第三方库(Mac osx Yosemite Intel i5环境)
    7.Python进阶_函数对象
    6.Python进阶_循环对象
    5.Python进阶_循环设计
    UltraEdit中粘贴问题
    UltraEdit的代码片的编码设置
    使用C#实现SSLSocket加密通讯 Https
    sql while 循环要加begin end
  • 原文地址:https://www.cnblogs.com/RootVount/p/10883819.html
Copyright © 2020-2023  润新知