POJ3176(DP)
来源:互联网 发布:sqlserver 删除表约束 编辑:程序博客网 时间:2024/06/09 20:16
大意:例
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
从上往下只能往左边或右边走,求沿途数字最大和。
分析:最简单的DP
代码:
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;int num[360][360];int dp[360][360];int main(){ //freopen("C:\\in.txt","r",stdin); int n,maxn=0; scanf("%d",&n); for(int i=0;i<n;i++) for(int j=0;j<=i;j++) scanf("%d",&num[i][j]); dp[0][0]=num[0][0]; for(int i=1;i<n;i++) for(int j=0;j<=i;j++) { if(j==0) dp[i][j]=dp[i-1][j]+num[i][j]; else if(j==i) dp[i][j]=dp[i-1][j-1]+num[i][j]; else dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+num[i][j]; } for(int i=0;i<n;i++) if(dp[n-1][i]>=maxn) maxn=dp[n-1][i]; cout<<maxn<<endl; // fclose(stdin); return 0;}
0 0
- poj3176 dp
- poj3176(DP)
- POJ3176(DP)
- poj3176 简单dp
- poj3176 Cow Bowling DP
- POJ3176 DP 数塔
- [dp]poj3176 Cow Bowling
- poj3176 dp 数字三角形
- POJ3176 简单DP....
- POJ3176 DP水题
- poj3176【简单DP】
- [DP]poj3176 Cow Bowling
- POJ3176-Cow Bowling(dp)
- POJ3176-Cow Bowling-简单dp
- poj3176
- poj3176
- poj3176
- poj3176
- java_web servlet第二课
- 配置eclipse jvm大小 配置 tomcat 内存大小
- Java NIO系列教程(11)Pipe
- 【卡通渲染】关于CG中的2D风格化
- 人脸特征点提取算法包对比(ASM/深度学习)
- POJ3176(DP)
- 改进冒泡排序
- 快乐课堂V2.3
- SURF与SIFT比较
- Android bluetooth介绍(四): a2dp connect流程分析
- Mongoose(二):快速开始
- 【Hibernate】——核心对象
- android 消息队列 ConcurrentLinkedQueue
- 2016网易安卓实习生offer经验