前言 记录遇到的通信中的数学优化方法。本文所介绍的是分式规划(Fractional Programming,FP)在以和速率最大化为目标的波束赋形问题求解中的应用。其关键思想有二: 利用 Lagrange 对偶将 SINR 项提取至 log 函数外面; FP 中的 二次变换(Quadratic Transform)。 FP 在通信中的应用有很
654. 最大二叉树 难度中等499收藏分享切换为英文接收动态反馈 给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建: 创建一个根节点,其值为 nums 中的最大值。 递归地在最大值 左边 的 子数组前缀上 构建左子树。 递归地在最大值
Given the root of a binary tree, collect a tree's nodes as if you were doing this: Collect all the leaf nodes. Remove all the leaf nodes. Repeat until the tree is empty. Solution 每次需要删去叶子节点。 我们利用 \(dfs\):对于叶子节点的,我们将其深度返回 \(-1\).
You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer destValue representing the value of the
给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建: 创建一个根节点,其值为 nums 中的最大值 递归地在最大值 左边 的 子数组前缀上 构建左子树 递归地在最大值 右边 的 子数组后缀上 构建右子树 1. 暴力分治构造 暴力在于每次递归都要找一次最大
https://www.acwing.com/problem/content/1625/ 思路: 注意这题dfs的写法,值得学习。 #include <iostream> using namespace std; const int N = 25; int n; int l[N], r[N]; string w[N]; bool st[N], is_leaf[N]; string dfs(int u) { string left, right; if (l[u]
基本思想:通过构造惩罚函数将约束问题转化为无约束问题,进而用无约束最优化方法求解。主要分为内点法和外点法。 注意:罚函数法对目标函数的凹凸性没有要求,且结合启发式算法(如遗传算法、蚁群算法、禁忌搜索等)几乎可以求解任何问题。因为启发式算法无需目标函数的梯度等信息。 一、
CSS 中的 position 属性用来设置元素在页面中的位置,通过该属性您可以把任何属性放置在任何您认为合适的位置。position 属性有 5 个可选值,分别对应 5 种不同的定位方式,如下所示: 取值说明 static 默认值,静态定位,表示没有定位,元素会按照正常的位置显示,此时 top、bottom、left 和
1. 直线和线段 假设 \(x_1\ne x_2\) 是 \(\mathbf{R}^n\) 空间(n维欧氏空间)中的两个点,直线 \[y=\theta x_1 + (1-\theta)x_2 \]是穿过 \(x_1\) 和 \(x_2\) 的直线,\(\theta\in \mathbf{R}\) 。若满足 \(\theta\in(0,1)\) ,则 \(y\) 为连接 \(x_1,x_2\) 的线段上的一点。 2. 仿射集(af
Given the root of a binary tree and two integers p and q, return the distance between the nodes of value p and value q in the tree. The distance between two nodes is the number of edges on the path from one to the other. Solution 求树上两个点之间的距离。很经
二分法代码笔记 最近复习二分法的题目,发现左右区间的二分写法总是无法第一时间写出正确的,故痛定思痛,通过写笔记的形式记录下来。 这里需要说明的是,二分法多用于单调情况下的LogN复杂度的搜索,并非只用于排序数组。二分法是一种高效的搜索方法,前提是能分析出问题是随某一个自变量的
\(\texttt{Problem 1}\) \(\texttt{Describe}\) 在小于 \(10\) 的自然数中,\(3\) 或 \(5\)的倍数有 \(3,5,6\) 和 \(9\),这些数之和是 \(23\)。 求小于 \(1000\) 的自然数中所有 \(3\) 或 \(5\) 的倍数之和。 \(\texttt{Solution}\) 可以考虑容斥,我们定义函数 \(S(x)\) 为小于 \(100
300. Longest Increasing Subsequence Medium Given an integer array nums, return the length of the longest strictly increasing subsequence. A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing t
The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. For example, for arr = [2,3,4], the median is 3. For example, for arr = [2,3], the m
优化问题的一般形式 在优化问题中,我们将其一般形式定义为有约束(不等式约束、等式约束)的最小化优化问题,其具体定义如下: \[\begin{array}{ll} \min _{x} & f_{0}(x) \\ \text { s.t. } & f_{i}(x) \leq 0, \quad i=1, \ldots, m \\ & h_{i}(x)=0, \quad i=1, \ldots, p \end{arr
最大矩形 dp+单调栈 对每一层维护本列中形成的最高值height,然后对每一层分别计算最大的矩形。 计算每一层最大矩形的时候,先用单调栈记录小于当前位置的左下标和右下标,矩形面积就是(right[i]-left[i]-1) * height[i] class Solution { public int maximalRectangle(char[][]
// """ // 给定一个非空列表,一层一层的构建一个二叉树。 // 例如: // input=[5,7,9,2,4,6,3,1,8,10] // 我希望返回结果: // 5(0) // / \ // 7(1) 9(2) // / \ / \ // 2(3) 4(4) 6(5) 3(6) // / \ / // 1(7) 8
101. 对称二叉树 给你一个二叉树的根节点 root , 检查它是否轴对称。 示例 1: 输入:root = [1,2,2,3,4,4,3] 输出:true 示例 2: 输入:root = [1,2,2,null,3,null,3] 输出:false 提示: 树中节点数目在范围 [1, 1000] 内 -100 <= Node.val <= 100 题解 根据此题相同的树的基础,
100. 相同的树 给你两棵二叉树的根节点 p 和 q ,编写一个函数来检验这两棵树是否相同。 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。 示例 1: 输入:p = [1,2,3], q = [1,2,3] 输出:true 示例 2: 输入:p = [1,2], q = [1,null,2] 输出:false 示例 3:
一、子空间的基 1、相关概念定义 若 \(S=\left\{ u_1,u_2,\cdots,u_m \right \}\) 是向量空间 \(V\) 的向量子集合,则 \(u_1,u_2,\cdots,u_m\) 的所有线性组合的集合 \(W\) 称为由 \(u_1,u_2,\cdots,u_m\) 张成的子空间,定义为 W=Span{u1,u2,⋯,um}={u:u=a1u1+a2u2+⋯+amum} 张成子
class ToDictMixin(object): def to_dict(self): return self._traverse_dict(self.__dict__) # 具体的实现代码写起来也很直观:我们只需要用hasattr函数动态地访问属性、isinstance函数动态地检测对象类型,并用 # dict_来访问实例内部的字典即可。
剑指 Offer II 047. 二叉树剪枝 难度中等42收藏分享切换为英文接收动态反馈 给定一个二叉树 根节点 root ,树的每个节点的值要么是 0,要么是 1。请剪除该二叉树中所有节点的值为 0 的子树。 节点 node 的子树为 node 本身,以及所有 node 的后代。 1 /** 2 * De
Matplotlib 定义了一个 axes 类(轴域类),该类的对象被称为 axes 对象(即轴域对象),它指定了一个有数值范围限制的绘图区域。在一个给定的画布(figure)中可以包含多个 axes 对象,但是同一个 axes 对象只能在一个画布中使用。 2D 绘图区域(axes)包含两个轴(axis)对象;如果是 3D 绘图区域,则包含三
思路 难度中等87收藏分享切换为英文接收动态反馈 给定一颗根结点为 root 的二叉树,树中的每一个结点都有一个 [0, 25] 范围内的值,分别代表字母 'a' 到 'z'。 返回 按字典序最小 的字符串,该字符串从这棵树的一个叶结点开始,到根结点结束。 注:字符串中任何较短的前
剑指 Offer II 046. 二叉树的右侧视图 难度中等33收藏分享切换为英文接收动态反馈 给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode