码迷,mamicode.com
首页 >  
搜索关键字:hdu 1394 minimum inv    ( 34217个结果
LeetCode OJ - Minimum && Maximum Depth of Binary Tree
这两道题用递归的解法都很简单,只是稍有不同。下面是AC代码: 1 /** 2 * Given a binary tree, find its minimum depth. 3 * the minimum depth is the number of nodes along th...
分类:其他好文   时间:2014-05-10 08:47:32    阅读次数:271
hdu 4276(树形dp)
题意:带权树上有起点终点每个点上有宝藏,一个人只有T分钟要从起点到重点,问你最多能收集多少宝藏。思路:树形dp,首先判断能不能走到终点,然后把路径上的边权变为0时间减去所有边权。dp[v][j]表示从v出发回到v话费j分钟最多能收集到的宝藏。dp[v][j] = max(dp[v][j], dp[x...
分类:其他好文   时间:2014-05-10 01:47:33    阅读次数:324
Leetcode: Minimum Depth of Binary Tree
这道题因为不仔细的缘故两次过,与Maximum Depth of Binary Tree问题类似,区别在于这个问题中,如果一个节点左子树为空、右子树有值,则该节点的深度应取决于右子树,而不能直接取min{左,右} 1 /** 2 * Definition for binary tree 3 * .....
分类:其他好文   时间:2014-05-10 01:40:13    阅读次数:293
Edit Distance
Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the fol...
分类:其他好文   时间:2014-05-10 01:09:28    阅读次数:325
Leetcode | Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have t...
分类:其他好文   时间:2014-05-09 19:09:35    阅读次数:318
HDU 3038 How Many Answers Are Wrong(种类并查集)
题目链接食物链类似的题,主要是在于转化,a-b的和为s,转换为b比a-1大s。然后并查集存 此节点到根的差。假如x的根为a,y的根为b:b - y = rank[y]a - x = rank[x]y - x = s可以推出b - a = rank[y] - rank[x] + s;并查集 延迟更新什...
分类:其他好文   时间:2014-05-09 18:38:05    阅读次数:213
HDU 3032 Nim or not Nim?(sg函数)
题目链接暴力出来,竟然眼花了以为sg(i) = i啊....看表要认真啊!!!#include #include #include using namespace std;#define LL __int64int dp[10001];int sg(int x){ int flag[10001...
分类:其他好文   时间:2014-05-09 18:00:34    阅读次数:274
LeetCode: Triangle 题解
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fol...
分类:其他好文   时间:2014-05-08 21:08:25    阅读次数:407
HDU 3998 Sequence(经典问题,最长上升子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3998解题报告:求一个数列的最长上升子序列,并求像这样长的不相交的子序列最多有多少个。我用的是最简单的方法,就是每次求最长上升子序列,然后每次将求得的子序列从数列里面删掉,然后再对剩下的数列求最长上升子序...
分类:其他好文   时间:2014-05-05 10:04:28    阅读次数:236
hdu 3501 Calculation 2 (欧拉函数)
题目题意:求小于n并且和n不互质的数的总和。思路:求小于n并且与n互质的数的和为:n*phi[n]/2 .若a和n互质,n-a必定也和n互质(a1是,phi(m)表示比m小且与m互质的正整数个数 1 #include 2 #include 3 #include 4 #include 5 #i...
分类:其他好文   时间:2014-05-05 09:50:27    阅读次数:396
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!