POJ 1163&& 3176 The Triangle(DP)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 41169 | Accepted: 24882 |
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 program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.
Input
all integers, are between 0 and 99.
Output
Sample Input
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output
30
Source
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> #define inf 9999
#define INF -9999 using namespace std; int n;
int dp[361][361]; int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
scanf("%d",&dp[i][j]);
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
dp[i][j] += max(dp[i-1][j-1],dp[i-1][j]);
}
}
int maxx = 0;
for(int i=1;i<=n;i++)
{
if(maxx<dp[n][i])
{
maxx = dp[n][i];
}
}
printf("%d\n",maxx);
}
return 0;
}
POJ 1163&& 3176 The Triangle(DP)的更多相关文章
- POJ 2193 Lenny's Lucky Lotto Lists (DP)
题目链接 题意 : 给你两个数N和M,让你从1到M中找N个数组成一个序列,这个序列需要满足的条件是后一个数要大于前一个数的两倍,问这样的序列有多少,输出. 思路 : dp[i][j]代表着长度为 i ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- Tour(dp)
Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)
Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...
随机推荐
- Express使用MongoDB常用操作
const MongoClient = require('mongodb').MongoClient const url = "mongodb://localhost:27017" ...
- javascrip 求最大公因数(分解质数法)发生的问题
//这是求一个数的质因数,例如:12=2*2*3 其中2,3都是质数.function primeArray(n, array) { array = new Array(); for (var i = ...
- [BZOJ4836]二元运算(分治FFT)
4836: [Lydsy1704月赛]二元运算 Time Limit: 8 Sec Memory Limit: 128 MBSubmit: 578 Solved: 202[Submit][Stat ...
- 【动态规划】Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
预处理每一层最左侧的1的位置,以及最右侧的1的位置. f(i,0)表示第i层,从左侧上来的最小值.f(i,1)表示从右侧上来. 转移方程请看代码. #include<cstdio> #in ...
- 查询续与ajax
查询分组 事例:统计不止一个作者的图书:(作者数量大于一) Book.objects.all().values('name').annotate(author_num=Count('authors__ ...
- ajax 同步和异步的区别
举个例子:普通B/S模式(同步)AJAX技术(异步)同步:提交请求->等待服务器处理->处理完毕返回 这个期间客户端浏览器不能干任何事异步: 请求通过事件触发->服务器处理(这时浏览 ...
- Mysql客户端下载地址
官网:http://dev.mysql.com/downloads/mysql/ 上述千万不要下载免安装版本. 千万记住一定要下载MSI安装版本.
- friend ---- public and private
I mean the difference between: class A{public: friend class B;};and class A{private: //or nothing as ...
- TWinHttp之二
TWinHttp之二 function EncodeParams(strings: TStrings): SockString;var i: Integer; S: string;begin for ...
- andriod 获得时间
import java.text.SimpleDateFormat;import java.util.Date; public static String getCurrentTime() { Sim ...