POJ1163 The Triangle: 倒三角形问题
经典的DP问题,DP思想也很直接:
直接贴代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int max_size=;
int n, a[max_size][max_size];
int f[][max_size];
void initiate(){
memset(a,-,sizeof(a));
memset(f,,sizeof(f));
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
scanf("%d",&a[i][j]);
}
}
}
void solve(){
int pt_row=n;
for(int column=;column<=n;column++){
f[pt_row%][column]=a[pt_row][column];
}
for(int row=n-;row>=;row--){
for(int pt_col=;pt_col<=row;pt_col++){
f[(pt_row-)%][pt_col]=a[pt_row-][pt_col]+max(
f[pt_row%][pt_col],
f[pt_row%][pt_col+]
);
}
--pt_row;
}
printf("%d\n",f[pt_row%][]);
}
int main(){
while(scanf("%d",&n)!=EOF){
initiate();
solve();
}
return ;
}
POJ1163 The Triangle: 倒三角形问题的更多相关文章
- POJ1163——The Triangle
Description 73 88 1 02 7 4 44 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program t ...
- POJ1163 The Triangle 【DP】
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36918 Accepted: 22117 De ...
- (数字三角形)POJ1163 The Triangle
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59698 Accepted: 35792 De ...
- POJ1163 The Triangle
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44997 Accepted: 27174 Description 73 ...
- Poj1163 The Triangle(动态规划求最大权值的路径)
一.Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a pro ...
- poj-3176 Cow Bowling &&poj-1163 The Triangle && hihocoder #1037 : 数字三角形 (基础dp)
经典的数塔模型. 动态转移方程: dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+p[i][j]; #include <iostream> #include ...
- 【HDOJ】1362 The Bermuda Triangle
1. 题目描述给定几个三角形拼成一个百慕大三角形. 2. 基本思路基本思路肯定是搜索,关键点是剪枝.(1) 若存在长度为$l$的边,则一定可以拼成长度为$k \cdot l$的三角形,则可拼成长度为$ ...
- [C++]2-3 倒三角形
/* 倒三角形(Triangle) 输入正整数n<=20,输出一个n层的倒等腰三角形. 0 ######### 9 = 2* n-1 1 ####### 7 = 2*(n-1)-1 2 #### ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
随机推荐
- Python开发轻量级爬虫
这两天自学了python写爬虫,总结一下: 开发目的:抓取百度百科python词条页面的1000个网页 设计思路: 1,了解简单的爬虫架构: 2,动态的执行流程: 3,各部分的实现: URL管理器:p ...
- 把Mvc4项目部署到虚拟目录之后找不到control想到的文件路径规范的问题
最近部署的项目的时候由于端口不够用,想到了把Mvc项目部署到虚拟目录中,结果发现图片,js设置control都找不到了.项目是mvc4+easyui开发的,大量的代码都是在js中调用control,写 ...
- Boost IPC Persistence Of Interprocess Mechanisms 例子
下面这一段摘抄自 Boost 1_55_0 的文档,显然标注了 每一个的生命期. One of the biggest issues with interprocess communication m ...
- Catch Application Exceptions in a Windows Forms Application
You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. Thi ...
- 【经验】angularjs 实现带查找筛选功能的select下拉框
一.背景 对于select的下拉列表,像国家选择这样的功能,全世界那么多国家,一直拉滚动条多辛苦,眼睛也要盯着找,累!so,为优化用户体验,带查找功能的下拉框是非常非常有必要的.都知道jquery里有 ...
- 数组方法slice()把类数组转成数组和复制一个数组
function a(){ console.log(arguments.length); var c = [].slice.call(arguments);//类数组转成数组 c.push(5); c ...
- sql里条件is null 在thinkphp里
$map['字段名'] = array('exp',' is NULL'); 譬如:$condition['url'] = array('exp',' is NULL');
- php数组遍历 使用foreach
<?php $url = array ( '新浪' =>'www.sina.com' , '雅虎' =>'www.yahoo.com' , '网易' =>'www.163.co ...
- 把硬盘格式化成ext格式的cpu占用率就下来了
把硬盘格式化成ext格式的cpu占用率就下来了我是使用ext4格式 @Paulz 还有这种事情? 现在是什么格式?- - ,你自己用top命令看一下啊就知道什么东西在占用cpu了下载软件一半cpu都用 ...
- 【HDOJ】1263 水果
hash,使用stl map ac.学了find_if等强大的东西,第一次使用stl模板. #include <iostream> #include <cstdio> #inc ...