
算法
包含PAT/POJ/LeetCode等算法和学习总结
供广大朋友学习与交流
……Riesling
爬坑骚年
展开
-
【高效复习】算法合集(一)——贪心和递归
贪心算法(PAT)A1067 Sort with Swap(0, i) (25 分)*Given any permutation of the numbers {0, 1, 2,…, N−1}, it is easy to sort them in increasing order. But what if Swap(0, ) is the ONLY operation that is al...原创 2019-02-19 22:03:23 · 497 阅读 · 0 评论 -
【高效复习】算法合集(二)——DFS和BFS
DFSDFS核心:构造递归,F(0)、F(1)是递归边界,递归式就是岔路口。枚举的思想+递归的表达方式:提示:类似全排列模板,给定一个序列,枚举这个序列的所有子序列(可以不连续)void DFS(int index, int sumw,int sumc){ if(index==n){ if(sumw<=v && sumc>maxvalu...原创 2019-02-21 19:50:54 · 221 阅读 · 0 评论 -
【高效复习】算法合集(三)——最短路径:Dijkstra、Bellman-ford、Spfa、Floyd
最短路径常用算法:dijkstra、bellman-ford、spfa、floyd一、Dijkstradijkstra用于解决单源点最短路径问题,对应所有边权都是非负的情况。对于有负数用spfa最好。其次用STL中的优先队列对待查的d[u]处理可以节省时间。dijkstra思路:设置集合S存放已被访问的顶点,然后执行n次下面的两个步骤:1)每次从集合v-s中选择与起点s的最短距离最小的...原创 2019-02-21 20:40:46 · 583 阅读 · 2 评论 -
【高效复习】算法合集 (四)——动态规划(LIS、LCS、01背包等)
动态规划(dynamic programming ,dp)一、DP简介一种用来解决一类最优化问题的算法思想特点:1)动态规划会将每个求解过的子问题的解记录下来。避免重复计算,使用dp[]以斐波那切数列为例:int F(int n){ if(n==0 || n==1) return 1; if(dp[n]!=-1) return dp[n]; //计算过时,直接返回...原创 2019-02-22 13:41:09 · 473 阅读 · 0 评论 -
[PAT]1018 Public Bike Management——Dijkstra+DFS
1018 Public Bike Management (30 分)一、原题There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and...原创 2019-02-21 23:16:53 · 186 阅读 · 0 评论 -
[PAT] A1034 Head of a Gang——DFS(字符处理)
(PAT) A1034 Head of a Gang (30 分)一、原文One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between A and B, we say that A and B is related. The ...原创 2019-02-22 00:07:58 · 155 阅读 · 0 评论 -
[PAT]A1076 Forwards on Weibo——BFS
(PAT)1076 Forwards on Weibo (30 分)一、原文Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is ...原创 2019-02-22 00:10:39 · 172 阅读 · 0 评论 -
[PAT]1030 Travel Plan——Dijkstra+DFS
1030 Travel Plan (30 分)A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to de...原创 2019-02-21 21:59:05 · 178 阅读 · 0 评论 -
[PAT]:1103 Integer Factorization——DFS
PAT:1103 Integer Factorization (30 分)The K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K...原创 2019-02-22 00:05:29 · 142 阅读 · 0 评论 -
[KTU]Yet another A + B——高精度
Yet another A + B一、原文time limit per test : 0.25 smemory limit per test : 64 MBinput : standard inputoutput : standard outputYou are given three numbers. Is there a way to replace variables A, B ...原创 2019-02-22 14:47:58 · 296 阅读 · 0 评论 -
[POJ]Wormholes——Bellman、SPFA
WormholesTime Limit: 2000MS Memory Limit: 65536K一、原文DescriptionWhile exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is...原创 2019-02-22 16:23:38 · 177 阅读 · 0 评论