zoukankan      html  css  js  c++  java
  • P1508-Likecloud-吃、吃、吃

     1 #include <bits/stdc++.h>
     2 #define maxn 13003
     3 #define _for(i,a,b) for(int i = (a);i < b;i ++)
     4 typedef long long ll;
     5 using namespace std;
     6 inline ll read()
     7 {
     8     ll ans = 0;
     9     char ch = getchar(), last = ' ';
    10     while(!isdigit(ch)) last = ch, ch = getchar();
    11     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
    12     if(last == '-') ans = -ans;
    13     return ans;
    14 }
    15 inline void write(ll x)
    16 {
    17     if(x < 0) x = -x, putchar('-');
    18     if(x >= 10) write(x / 10);
    19     putchar(x % 10 + '0');
    20 }
    21 int n,m; 
    22 int ap[203][203];
    23 int dp[203][203];
    24 
    25 int main()
    26 {
    27     n = read(), m = read();
    28     memset(dp,0,sizeof(dp));
    29     _for(i,0,n)
    30         _for(j,0,m)
    31             ap[i][j] = read();
    32     
    33     _for(i,0,m)
    34     {
    35         if(i>=m/2-1 && i<=m/2+1)
    36             dp[n-1][i] = ap[n-1][i];
    37         else
    38             dp[n-1][i] = -1000000;
    39     }
    40     
    41     for(int i = n-2;i >= 0;i --)
    42     {
    43         for(int j = 0;j < m;j ++)
    44         {
    45             if(j>=1)
    46                 dp[i][j] = dp[i+1][j-1]+ap[i][j];
    47             dp[i][j] = max(dp[i][j],dp[i+1][j]+ap[i][j]);
    48             if(j<=m-2)
    49                 dp[i][j] = max(dp[i][j],dp[i+1][j+1]+ap[i][j]);
    50         }
    51     }
    52     
    53     int rnt = 0;
    54     _for(i,0,m)
    55         rnt = max(rnt,dp[0][i]);
    56     write(rnt);
    57     return 0;
    58 }
  • 相关阅读:
    #define #undef
    ps
    Find–atime –ctime –mtime的用法与区别总结
    redis
    linux mutex
    private继承
    boost::noncopyable介绍
    Makefile 中:= ?= += =的区别
    linux Tar 命令参数详解
    Ubuntu14.04安装CMake3.0.2
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11334056.html
Copyright © 2011-2022 走看看