poj 1163&3176 DP
来源:互联网 发布:java算法书籍 编辑:程序博客网 时间:2024/06/06 19:20
两个其实是一个题,给一个三角形,往里填满数,从上到下走一趟,求路过数字的和的最大值。
动态规划的第一道吧 - -,记忆化搜索 <注意边界!>
#include <cstdio>#include<string.h>using namespace std;const int maxn =102;int h,a[maxn][maxn],d[maxn][maxn];int dp(int i,int j){ if(d[i][j]>=0) return d[i][j]; return d[i][j]=a[i][j]+(i==h?0: (dp(i+1,j)>dp(i+1,j+1)?dp(i+1,j):dp(i+1,j+1)) );}int main(){ while(~scanf("%d",&h)) { for(int i=1;i<=h;i++) for(int j=1;j<=i;j++) scanf("%d",&a[i][j]); memset(d,-1,sizeof(d)); printf("%d\n",dp(1,1)); } return 0;}
0 0
- poj 1163&3176 DP
- poj 1163/3176 数字三角形【简单DP】
- POJ 1163&& 3176 The Triangle(DP)
- poj 1163 The Triangle &poj 3176 Cow Bowling (dp)
- POJ 3176 简单DP
- poj 3176 dp
- POJ 3176 简单DP
- poj 1163经典DP
- POj 1163 DP
- poj 1163 DP
- poj 1163 DP
- POJ 3176 Cow Bowling DP
- poj-3176-Cow Bowling-dp
- poj 3176 Cow Bowling (DP)
- poj 3176 Cow Bowling dp
- POJ 3176 Cow Bowling DP
- poj 3176Cow Bowling DP
- POJ 3176 : Triangle - 水DP
- java jprofiler 内存泄露
- Android SDK提供了2个主要的剖析应用程序内存使用情况的工具
- 软件性能测试读书笔记(1)
- 关于取消的默认的Enter的keydown事件的疑问与解决
- Android 学习笔记11:Activity
- poj 1163&3176 DP
- 回忆2013-----在路上
- 提升Android应用开发性能的十大要点
- 局部变量与成员变量不得不说的秘密!
- Android移植oprofile性能监测工具
- Makefile基础 4. 自动处理头文件的依赖关系
- SQL优化-索引
- 山寨版360安全卫士 腾讯电脑管家开源(.NET实现)
- Jquery uplodify 3.2 使用(2)