poj3176【简单DP】

其实就是简单递推对吧~
贴一发记忆化搜索的…

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
const double pi = acos(-1.0);
const int mod = 1e9+7;

const int N =355;
int a[N][N];
int dp[N][N];
int n;
int dfs(int x,int y)
{
    if(dp[x][y]!=-1)
        return dp[x][y];
    if(x==n)
        return dp[x][y]=a[x][y];
    int temp=0;
    if(x+1<=n)
        temp=max(temp,max(dfs(x+1,y),dfs(x+1,y+1)));
    return dp[x][y]=temp+a[x][y];
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
            scanf("%d",&a[i][j]);

    memset(dp,-1,sizeof(dp));

    printf("%d\n",dfs(1,1));
    return 0;
}

再贴一发递推的…………e…算了…
给个传送门,做个稍微难的(加个路径输出),题目是一样的。

posted @ 2016-08-08 15:38  see_you_later  阅读(91)  评论(0编辑  收藏  举报