zoukankan      html  css  js  c++  java
  • [洛谷] P1508 吃吃吃

    简单DP

    注意最后取值即可

    //#pragma GCC optimize(2)
    #include <cstdio>
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <set>
    #include <map>
    #include <ctime>
    #include <vector>
    #include <fstream>
    #include <list>
    #include <iomanip>
    #include <numeric>
    using namespace std;
    #define int long long
    const int MAXN = 2e3 + 10;
    
    int arr[MAXN][MAXN];
    int dp[MAXN][MAXN];
    
    int n, m;
    
    signed main()
    {
        //ios::sync_with_stdio(false);
        //cin.tie(0);     cout.tie(0);
        //freopen("D://test.in", "r", stdin);
        //freopen("D://test.out", "w", stdout);
        
        cin>>n>>m;
    
        int mid = m / 2 + 1;
    
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
                cin>>arr[i][j];
    
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
                dp[i][j] = max(max(dp[i-1][j], dp[i-1][j-1]), dp[i-1][j+1]) + arr[i][j];
    
        int ans = -0x3f3f3f3f;
    
        
        ans = max(max(dp[n][mid-1],dp[n][mid]),dp[n][mid+1]);
        
        cout<<ans<<endl;
    
        return 0;
    }
    
  • 相关阅读:
    ye间模式
    Xutilt网络获取数据
    JUnit
    IntelliJ IDEA快捷键
    Map存放不同数据或对象
    SQL改
    外键约束
    Hibernate之SQL语言查询
    Hibernate之Criteria语言查询
    Hibernate之HQL语言查询
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270426.html
Copyright © 2011-2022 走看看