poj1163 【记忆化搜索·水】

题意:
一个这样的三角形,他可以往下的左或者往下的右走。求一个在最后一行的最大。
思路:
额。。。就是搜一下。。记录一下。。。肯定有重合的情况。

code…

//#include <bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double eps=1e-6;
const double pi=acos(-1.0);
const int mod=998244353;
const int INF=0x3f3f3f3f;

const int N=1e2+10;

int dp[N][N];
int a[N][N];
int n;

int dfs(int x,int y)
{
    if(dp[x][y]!=-1)
        return dp[x][y];
    int ans=0;
    if(x-1>=1)
        ans=max(dfs(x-1,y),ans);
    if(y-1>=1&&x-1>=1)
        ans=max(dfs(x-1,y-1),ans);
    return dp[x][y]=(ans+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]);
    int ans=0;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
        ans=max(dfs(n,i),ans);
    cout<<ans<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值