poj3176【简单DP】
2024-08-30 06:49:10
其实就是简单递推对吧~
贴一发记忆化搜索的…
#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…算了…
给个传送门,做个稍微难的(加个路径输出),题目是一样的。
最新文章
- 搭建LNAMP环境(二)- 源码安装Nginx1.10
- [Java IO]02_字节流
- (ios) nsnotification总结
- 执行sudo时报错:effective uid is not 0
- Java引用机制——reference
- HDU 4417 (划分树+区间小于k统计)
- String对象的方法
- 《C标准库》——之<;stdarg.h>;
- Sqli-labs less 26a
- 有关Ant编译
- 利用linq快速判断给定数字是否包含在某个段范围内
- 001Spark文件分析测试
- hdu 4741 Save Labman No.004(2013杭州网络赛)
- Android学习之 AChartEngine 图表绘制
- jsp-2 简单的servlet连接mysql数据库 增删改查
- Python笔记&#183;第四章—— 细数Python中的数据类型以及他们的方法
- HTTP响应状态码含义参考
- Java小知识点总结
- 算法笔记--FFT
- Java如何处理已检查异常?
热门文章
- 一种排序(nyoj8)(简单排序)
- CodeForces 321A Ciel and Robot(数学模拟)
- [iOS]APP代码实践:建立一个辅助的APP类,降低对AppDelegate的改动
- SpringBoot学习之启动报错【This application has no explicit mapping for /error.....】
- MergeLinklist
- Django-配置celery
- BEGINNING SHAREPOINT&;#174; 2013 DEVELOPMENT 第8章节--配送SP2013Apps 应用程序生命周期
- 1987年国际C语言混乱代码大赛获奖的一行代码
- MVC程序部署后页面指向login.aspx
- iOS的基本框架