nyist 18---- hdu 2048----poj 1163-----rwkj 1143

//记忆式搜索
#include<iostream>
#include<string.h>
using namespace std;
int a[101][101],n,b[101][101];

int f(int i,int j)
{ if ( b[i][j]!=-1 ) return b[i][j];

if ( i==n-1) return b[i][j]=a[i][j];

else return b[i][j]=a[i][j]+max(f(i+1,j),f(i+1,j+1));
}

int main()
{
int i,j;
memset(b,-1,sizeof(b));
cin>>n;
int maxn=0;
for (i=0;i<n;i++)
for ( j=0;j<=i;j++)
cin>>a[i][j];
cout<<f(0,0)<<endl;
return 0;
}

#include <iostream>
#include<string.h>
using namespace std;
int a[1005][1005],b[1005][1005];
int n;
int max(int x, int y)
{ return x>y?x:y ; }

int f(int i,int j)
{
if(b[i][j]!=-1) return b[i][j];
return b[i][j]=a[i][j]+max(f(i+1,j),f(i+1,j+1));
}

int main()
{
int i,j;

while(cin>>n)
{

for(i=0;i<n;i++)
for(j=0;j<=i;j++) cin>>a[i][j];
memset(b,-1,sizeof(b));
for(j=0;j<n;j++) b[i-1][j]=a[i-1][j];
cout<<f(0,0)<<endl;
}

}

nyist 18---- hdu 2048----poj 1163-----rwkj 1143

时间: 2024-08-29 23:08:46

nyist 18---- hdu 2048----poj 1163-----rwkj 1143的相关文章

hdu 2084 &amp; POJ 1163 数塔 (dp)

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 24626    Accepted Submission(s): 14814 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少

Eight hdu 1043 poj 1077

Description The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile mis

JAVA HDU 2048 神、上帝以及老天爷

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2048 一开始用的System.out.printf("%.2f%%\n", result)输出,PRESENTATION ERROR.  换成System.out.println(String.format("%.2f", result)+"%")就好了 1 package hdu; 2 3 import java.io.BufferedInputS

hdu 1541/poj 2352:Stars(树状数组,经典题)

Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4052    Accepted Submission(s): 1592 Problem Description Astronomers often examine star maps where stars are represented by points on a plan

hdu 3934&amp;&amp;poj 2079 (凸包+旋转卡壳+求最大三角形面积)

链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 8173   Accepted: 2423 Description Given n distinct points on a plane, your task is to find the triangle that have the maximum area, whose vertices

递推DP POJ 1163 The Triangle

题目传送门 1 /* 2 数塔 3 自底向上 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <cstring> 8 #include <string> 9 #include <algorithm> 10 #include <cmath> 11 using namespace std; 12 13 const int MAXN = 100 + 10; 14 const

HDU 1116 || POJ 1386 || ZOJ 2016 Play on Words (欧拉回路+并查集)

题目链接 题意 : 有很多门,每个门上有很多磁盘,每个盘上一个单词,必须重新排列磁盘使得每个单词的第一个字母与前一个单词的最后一个字母相同.给你一组单词问能不能排成上述形式. 思路 :把每个单词看成有首字母指向尾字母的有向边,每个字母看成一个点,题中要求等效于判断图中是否存在一条路径经过每一条一次且仅一次,就是有向欧拉通路.统计个顶点的出入度,如果每个点的出入度都相同,那就是欧拉回路,如果有两个奇数度,那就是欧拉通路,除此之外,都不能满足要求.还有别忘了判断是否连通,此时用到并查集,图中所有的边

神、上帝以及老天爷 HDU - 2048(错排)

神.上帝以及老天爷 HDU - 2048 错排~ c[n] = (n-1) * (c[n-1] + c[n-2]); c[1] = 0; c[2] = 1; 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 const int mod = 20090126; 5 const int maxn = 21; 6 ll c[maxn], f[maxn]; 7 void init(){ 8 c[1] =

HDU 1087 &amp;&amp; POJ 2533(DP,最长上升子序列).

~~~~ 两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度. 貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛.. ~~~~ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 http://poj.org/problem?id=2533 ~~~~ HDU1087: #include<cstdio> #include<cstring> #include<algorithm> #

hdu 2844 poj 1742 Coins

hdu 2844 poj 1742 Coins 题目相同,但是时限不同,原本上面的多重背包我初始化为0,f[0] = 1;用位或进行优化,f[i]=1表示可以兑成i,0表示不能. 在poj上运行时间正好为时限3000ms....太慢了,hdu直接TLE(时限1s); 之 后发现其实并不是算法的问题,而是库函数的效率没有关注到.我是使用fill()按量初始化的,但是由于memset()可能是系统底层使用了四个字节拷 贝的函数(远比循环初始化快),效率要高得多..这就是为什么一直TLE的原因,fil