数字三角形(POJ1163)Description73 88 1 02 7 4 44 5 2 6 5在上面的数字三角形中寻找一条从顶部到底边的路径,使得路径上所经过的数字之和最大。路径上的每一步都只能往左下或右下走。只需要求出这个最大和即可,不必给出具体路径。...
分类:
其他好文 时间:
2015-02-11 16:13:29
阅读次数:
984
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 ...
分类:
其他好文 时间:
2015-02-08 16:46:31
阅读次数:
135
Given a binary tree, find the maximum path sum.
The path may start and end at any node in the tree.
求树的一点到另一点的最大路径,利用递归的方法,ans 在 左子树,右子树,root+左+右的最大中产生。
/**
* Definition for binary tree
* struct ...
分类:
其他好文 时间:
2015-01-27 22:01:36
阅读次数:
112
AC代码:
#include
#include
#include
#include
#include
using namespace std;
#define INF 123456
#define MAX_V 35
#define MAX_E 1005
double d[MAX_V][MAX_V];
int n, m;
void Floyd(){
for(int k=1;...
分类:
其他好文 时间:
2015-01-21 18:16:14
阅读次数:
141
Marriage Match II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2307 Accepted Submission(s): 792
Problem Description
Presumably, y...
分类:
其他好文 时间:
2015-01-19 12:53:17
阅读次数:
146
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example:Given the below binary tree, 1 / \ 2 3...
分类:
其他好文 时间:
2015-01-06 17:38:16
阅读次数:
199
最优路径问题package 数阵中的最优路径;import java.util.Scanner;public class Main { /** * 数值三角形中的最大路径 * 随机产生一个n行的点数值三角形(第k行有k个点,每个点都带有一个正整数,)寻找从顶点开始每一步可沿着左...
分类:
其他好文 时间:
2015-01-06 15:16:20
阅读次数:
113
此题可以用bellman-ford算法来求解。bellman-ford算法是求解最短路径,此题是求解
“最大路径”,条件与松弛条件相反,因此求的是无限松弛的最大正权路径,可以用bellman-ford算法去解题。
此题中的“最大路径”其实就是求改变点数下是否有增加更新点。
我们用dis[i]来表示第i种货币的钱数。
我们求最大那么需将dis[i]初始话为0,再用bellman-fo...
分类:
其他好文 时间:
2014-12-25 22:10:42
阅读次数:
230
由于权值是在边上,所以很容易发现一个性质:d(x,y)=d(x,root) xor d(y,root)。 因为有了这个性质,那么就很好做了。对于每一个点统计到root的距离,记为f 数组。 将f数组里的每个值插进按照二进制位插进字典树里面。 枚举每一个点,然后在字典树中搜索最大的xor值就...
分类:
其他好文 时间:
2014-12-16 22:21:45
阅读次数:
232
题目大意:给出一个无向有权图,找出一条从1到n的路径,使得路径上权值的异或和最大,路径可以重复走Input第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目。 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 Di的无向边。 图中可能有重...
分类:
其他好文 时间:
2014-12-14 15:42:46
阅读次数:
139