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 following triangle [ [], [,4], [6,,7], [4,,8,3] ] The minimum path sum from top to bottom is 11 (i.e.,…
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. 这道题跟之前那道Dungeon Game 地牢游戏 没有什么太大的…
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 following triangle [ [], [,4], [6,,7], [4,,8,3] ] The minimum path sum from top to bottom is 11 (i.e.,…
小Hi:在上一周的Hiho一下中我们初步讲解了网络流的概念以及常规解法,小Ho你还记得内容么? 小Ho:我记得!网络流就是给定了一张图G=(V,E),以及源点s和汇点t.每一条边e(u,v)具有容量c(u,v).网络流的最大流问题求解的就是从s到t最多能有多少流量. 小Hi:那这个问题解决办法呢? 小Ho:解决网络流的基本思路就是寻找增广路,不断更新残留网络.直到找不到新的增广路,此时得到的流就是该网络的最大流. 小Hi:没错,看来你记得很牢嘛. 小Ho:哎嘿嘿,不过这里我有一个问题,为什么找不…
For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1. Now given a string representing n, you should return the smallest good base of n in string format. Example 1: Input: "13" Output: "3" Explanation: 13…
原题地址:https://oj.leetcode.com/problems/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 following triangle [ [], [,4], [6,,7], [4,,8,3] ]…
链接: http://poj.org/problem?id=2253 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#problem/D Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21206   Accepted: 6903 Description Freddy Frog is sitting on a stone in the…
Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理) 题目描述 一条报文包含字母A-Z,使用下面的字母-数字映射进行解码 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给一串包含数字的加密报文,求有多少种解码方式 举个例子,已知报文"12",它可以解码为AB(1 2),也可以是L (12) 所以解码方式有2种. 测试样例 Input: "0" "121212" "1010…
题目链接:https://vjudge.net/problem/POJ-1797 题意:n个点,m条带权边,求点1到点n的所有路径中最小边的最大值. 思路: 和poj2253一样,只不过那题n<=200,可以用floyd,而这题floyd会TLE,所以用dijkstra来做. 提一下floyd的做法,用dp[i][j]表示i到j的所有路径中最小边的最大值,那么转移方程是: dp[i][j]=max(dp[i][j] , min(dp[i][k] , dp[k][j]) ). dijkstra的做…
Leetcode不同路径系列题解笔记 62. 不同路径 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 "Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为 "Finish" ).问总共有多少条不同的路径? 两种解法:1. 简单的动态规划   2.计算组合值 (总共可以走m+n-2步,向下走需要选择n-1步) class Solution: def uniquePaths(self, m: int…
=================================版权声明================================= 版权声明:原创文章 谢绝转载  请通过右侧公告中的“联系邮箱(wlsandwho@foxmail.com)”联系我 勿用于学术性引用. 勿用于商业出版.商业印刷.商业引用以及其他商业用途. 本文不定期修正完善. 本文链接:http://www.cnblogs.com/wlsandwho/p/4930415.html 耻辱墙:http://www.cnblo…
Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 21453   Accepted: 9297 Case Time Limit: 5000MS Description As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Officer of TinySoft Co…
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1001 1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 17068  Solved: 4171[Submit][Status][Discuss] Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两…
题意:有个一字符串A(本身不是循环串),然后经过很多次自增变成AAAAA,然后呢从自增串里面切出来一部分串B,用这个串B求出来A的长度.   分析:其实就是求最小循环节.......串的长度 - 最大的匹配. 代码如下. =========================================================================================================== #include<stdio.h> #include<…
题意 求所有循环次数大于1的前缀 的最大循环次数和前缀位置 解法 直接用KMP求最小循环节 当满足i%(i-next[i])&&next[i]!=0 前缀循环次数大于1 最小循环节是i-next[i] #include <cstdio> #include <cstring> #include <iostream> #include <cstdlib> using namespace std; char S[2000000]; int NEXT…
这个函数是我无意中看到的很不错,很给力,我喜欢 是用于求最小公约数的 简单的描述就是,记gcd(a,b)表示非负整数a,b的最大公因数,那么:gcd(a,b)=gcd(b,a%b)或者gcd(a,0)=gcd(0,a)=a 请看代码 int gcd(int a,int b){ if(a==0) return b; if(b==0) return a; return gcd(b,a%b);} 例题 链接 http://acm.hdu.edu.cn/showproblem.php?pid=1108…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3035 题意 给个图,求把s和t分开的最小割. 分析 实际顶点和边非常多,不能用最大流来求解.这道题要用平面图求最小割的方法: 把面变成顶点,对每两个面相邻的边作一条新边.然后求最短路就是最小割了. 另外,外平面分成两个点,分别是源点和汇点,源点连左下的边,汇点连右上的边,这样跑出来才是正确的. 建图参考自:https://blog.csdn.net/accelerator_/article/deta…
Assignment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1698    Accepted Submission(s): 901 Problem Description Last year a terrible earthquake attacked Sichuan province. About 300,000 PLA so…
描述 The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located at vertices of regular polygons. The moving sand dunes of the desert render the excavations difficult and thus once three vertices of a polygon are di…
妖怪题目,做到现在:2017/8/19 - 1:41…… 不过想想还是值得的,至少邻接矩阵型的Dinic算法模板get√ 题目链接:http://poj.org/problem?id=1815 Time Limit: 2000MS Memory Limit: 20000K Description In modern society, each person has his own friends. Since all the people are very busy, they communic…
====数组篇==== 2.1 求最小的k个数: 题目描述:有n个整数,请找出其中最小的k个数,要求时间复杂度尽可能低. 解法一: 思路:快排后输出前k个元素,O(nlogn). writer: zzq function: 给定一个数组,寻找数组中最小的k个数. 方法一: 先对数组进行排序(快排), 然后选择前k个数. 快排思想: 分治+挖坑 挖坑: 1) 先找到一个基准值a[i],存到key里面,然后把a[i]挖空: 2) 从j开始往前找(j--),找到第一个比key小的数,就用当前的a[j]…
旋转卡壳求最小矩形覆盖的模板题. 因为最小矩形必定与凸包的一条边平行,则枚举凸包的边,通过旋转卡壳的思想去找到其他3个点,构成矩形,求出最小面积即可. #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<stack&g…
Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少次得到. analyse: KMP之next数组的运用.裸的求最小循环节. Time complexity: O(N) Source code:  ;;      ;);      ) ;}/* */…
The Minimum Length Problem's Link: http://acm.hust.edu.cn/problem/show/1010 Mean: 给你一个字符串,求这个字符串的最小循环节. analyse: KMP之next数组的运用.裸的求最小循环节. Time complexity: O(N) Source code:  ;;;);      ;}/* */…
Cyclic Nacklace Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3746 Mean: 给你一个字符串,让你在后面加尽量少的字符,使得这个字符串成为一个重复串. 例: abca---添加bc,成为abcabc abcd---添加abcd,成为abcdabcd aa---无需添加 analyse: 经典的求最小循环节. 首先给出结论:一个字符串的最小循环节为:len-next[len]. 证明: 举个例子:abcab…
题面: [ZJOI2011]最小割 [CQOI2016]不同的最小割 题解: 其实这两道是同一道题.... 最小割是用的dinic,不同的最小割是用的isap 其实都是分治求最小割 简单讲讲思路吧 就是首先全部的点都在一个集合里,然后随意定两个点为s和t,这里默认是第一个和最后一个. 然后找到最小割,最小割将整张图分为了s集和t集,于是我们再用这个最小割更新跨集合点对之间的最小割. 这个很好理解,因为当前找到的最小割将s集和t集分开了,显然对于任意一组跨集合的点对而言,当前最小割都是一个可能的最…
/** 题目:hdu6003 Problem Buyer 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6003 题意:给定n个区间,以及m个数,求从n个区间中任意选k个区间,满足m个数都能在k个区间中找到一个包含它的区间,如果一个区间包含了x,那么 该区间不能再去包含另一个数,即k>=m.求最小的k.如果不存在这样的k,输出“IMPOSSIBLE!”. 思路:贪心; 对n个区间,先左端点进行由小到大排序,然后右端点由大到小.对m个数由小到大排序. 对…
/** 题目:poj3565 Ants km算法求最小权完美匹配,浮点权值. 链接:http://poj.org/problem?id=3565 题意:给定n个白点的二维坐标,n个黑点的二维坐标. 求是否存在n条边,每条边恰好连一个白点,一个黑点,且所有的边不相交. 输出所有黑点连接的白点编号. 思路:最小权完美匹配. 假定有白点1(a1,b1), 2(a2,b2), 黑点3(a3,b3),4(a4,b4); 如果1(a1,b1)与3(a3,b3)相连,2(a2,b2)与4(a4,b4)相连,如…
LeetCode:路径总和II[113] 题目描述 给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径. 说明: 叶子节点是指没有子节点的节点. 示例:给定如下二叉树,以及目标和 sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 返回: [ [5,4,11,2], [5,8,4,5] ] 题目分析 首先是一个深度搜索,来把所有根节点到叶子节点的路径找出来,然后各自判断是否等于目标值,等于目标值的路径加入结果集中.这…
扩展欧几里得算法模板 #include <cstdio> #include <cstring> #define ll long long using namespace std; ll extend_gcd(ll a, ll b, ll &x, ll &y) { ) { x = , y = ; return a; } else { ll r = extend_gcd(b, a%b, y, x); y -= x*(a/b); return r; } } 1.对于形如a…