poj 2498 动态规划

思路:简单动态规划

#include<map>

#include<set>

#include<cmath>

#include<queue>

#include<cstdio>

#include<vector>

#include<string>

#include<cstdlib>

#include<cstring>

#include<iostream>

#include<algorithm>

#define pb push_back

#define mp make_pair

#define Maxn 520

#define Maxm 80002

#define LL __int64

#define Abs(x) ((x)>0?(x):(-x))

#define lson(x) (x<<1)

#define rson(x) (x<<1|1)

#define inf 0x7fffffff

#define lowbit(x) (x&(-x))

#define Mod 1000000007

using namespace std;

int dp[Maxn][Maxn],ye[Maxn][Maxn],bio[Maxn][Maxn];

int main()

{

    int n,m,i,j;

    while(scanf("%d%d",&n,&m)!=EOF,n||m){

        memset(dp,0,sizeof(dp));

        for(i=1;i<=n;i++){

            for(j=1;j<=m;j++){

                scanf("%d",&ye[i][j]);

                ye[i][j]+=ye[i][j-1];

            }

        }

        for(i=1;i<=n;i++){

            for(j=1;j<=m;j++){

                scanf("%d",&bio[i][j]);

                bio[i][j]+=bio[i-1][j];

            }

        }

        for(i=1;i<=n;i++){

            for(j=1;j<=m;j++){

                dp[i][j]=max(dp[i-1][j]+ye[i][j],dp[i][j-1]+bio[i][j]);

            }

        }

        printf("%d\n",dp[n][m]);

    }

    return 0;

}

 

你可能感兴趣的:(动态规划)