这题是明显的TU包变形。使用卷包裹法可解,而且是必定可以经过所有点的。直观可知,当经过某点后,相当于把之前的点抹去,求剩下点的TU包,递归下去,也就能把点全部经过了。于是,只需把经过的点标记一下就可以了。#include #include #include #include #include usi...
分类:
其他好文 时间:
2014-07-30 23:51:15
阅读次数:
349
直接递归
代码:
#include
#include
using namespace std;
typedef struct listNode{
int key;
struct listNode *pNext;
} * pNode,Node;
void createNode(pNode &pHead){
bool isFirst=true;
int temp;
sc...
分类:
其他好文 时间:
2014-07-30 20:57:14
阅读次数:
174
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 ...
分类:
其他好文 时间:
2014-07-30 20:33:34
阅读次数:
193
递归#include #include #include #define NUM 4int total = 0;void print_board(int *board){ printf("\n"); for (int i = 0; i < NUM; i++) { fo...
分类:
其他好文 时间:
2014-07-30 20:20:54
阅读次数:
188
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n)
space is pretty straight...
分类:
其他好文 时间:
2014-07-30 17:46:04
阅读次数:
244
使用数据结构stack或者递归
1 使用stack
#include
#include
using namespace std;
typedef struct listNode{
int key;
struct listNode *pNext;
} * pNode,Node;
void createNode(pNode &pHead){
bool isFirst=true;...
分类:
其他好文 时间:
2014-07-30 17:30:34
阅读次数:
189
/**
?*?@param?args
?*/
public?static?void?main(String[]?args)?{
char[]?raw?=?"12345".toCharArray();
perm(raw,?4);
// System.out.println("===========================");
// Syst...
分类:
其他好文 时间:
2014-07-30 15:07:14
阅读次数:
182
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center)....
分类:
其他好文 时间:
2014-07-30 14:48:53
阅读次数:
216
一、概念:(Recursion)在数学与计算机科学中,是指在函数定义中使函数自身的方法。 定义: 在数学和计算器及科学中,递归是指由一种(或多种)简单的基本情况定义的一类对象或方法,并规定其它所有情况都能被还原为其基本情况。http://zh.wikipedia.org/zh/%E9%80%92.....
分类:
其他好文 时间:
2014-07-30 11:50:53
阅读次数:
201
1 概述 算法(Algorithm)是指解题方案的准确而完整的描述,是一系列解决问题的清晰指令,算法代表着用系统的方法描述解决问题的策略机制。一个算法的优劣可以用空间复杂度和时间复杂度来衡量。2 特征 一个算法应该有一下五个重要特征:有穷性、确切性、输入项、输出项、可行性。3 要素 一,数据对...
分类:
其他好文 时间:
2014-07-30 11:48:53
阅读次数:
215