随笔分类 -  模板

摘要:#include #include #include using namespace std;int C[1100];const int MAXN = 10;void update(int x, int ans){ C[x] = ans ; while(x 0){ ret... 阅读全文
posted @ 2015-10-21 20:27 Painting、时光 阅读(480) 评论(0) 推荐(0)
摘要:Bellman_ford:复杂度:O(VE) 边数用途:一条路,钱币的互换,寻找最小正权环,即一圈后能回到自己并且比自己大或者小,如果是大,d数组就开0,否则开inf适用条件:从源点到它的所有节点,适用于稀疏图(顶点多,边数少)原理:利用该顶点判断操作之后与操作之前的比较步骤:1.开一个d数组,以d... 阅读全文
posted @ 2015-10-10 20:29 Painting、时光 阅读(224) 评论(0) 推荐(0)
摘要:用来求组合数取模ll Lucas(ll n, ll m, int p){ return 1ll * comb(n%p, m%p) * Lucas(n/p, m/p, p);} 阅读全文
posted @ 2015-10-01 16:39 Painting、时光 阅读(136) 评论(0) 推荐(0)
摘要:哈希表:建表复杂度:O(n) k为字符串品均长度,n为字符串数目查询 O(1) !!!实现主要操作1.把字符串进行实数化2.把这个串存进去如果发现该位置为空,直接存,如果已经有了值,拉出一个链表3.查询该算法好像是不会产生冲突,因为一旦产生冲突,那么strcmp字符串函数就会对他们进行比较,虽然复杂... 阅读全文
posted @ 2015-09-04 19:38 Painting、时光 阅读(488) 评论(0) 推荐(0)
摘要:不能处理有环的图void SPFA(){ memset(vis, false, sizeof(vis)); vis[1] = true; for(int i = 1; i d[u] + w){ d[v] = d[u] + w; ... 阅读全文
posted @ 2015-08-26 16:26 Painting、时光 阅读(104) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5294SPFA:Bellman_Ford的队列优化算法无法处理带负环的图复杂度O(kE) k #include #include #include #include #include #include #inclu... 阅读全文
posted @ 2015-08-26 16:17 Painting、时光 阅读(181) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1273最大流算法:一张图有一个源点一个汇点,中间有很多要经过的点,点与点之间有最大流量的限制,问从源点到汇点的最大每秒流量是多少加入了残余网络和增广路这两个概念残余网络:是对于一次处理之后得到得剩下的图增广路:对于u到i的的流量我少了x容量那么i... 阅读全文
posted @ 2015-08-24 20:37 Painting、时光 阅读(146) 评论(0) 推荐(0)
摘要:/************************************************Author :powatrCreated Time :2015-8-5 21:06:30File Name :b.cpp****************************... 阅读全文
posted @ 2015-08-05 21:16 Painting、时光 阅读(121) 评论(0) 推荐(0)
摘要:#include#include#include#include//greater 使得从小到大 ,less反//priority_queue, less > que 相当于 priority_queue que#includeusing namespace std;const int MAX =... 阅读全文
posted @ 2015-07-19 15:59 Painting、时光 阅读(511) 评论(0) 推荐(0)
摘要:/*莫队算法是离线算法,用来解决已知l,r问你l,r里面值的问题对块进行排序,后面的块通过前面的块左移右移得到,所以可能有的情况能得到O(1)或者较低的复杂度排序的时候除以跟好n(?)本题题意:从l到r区间内问有多少个不同的数,询问很多*/#include#include#include#inclu... 阅读全文
posted @ 2015-07-16 20:53 Painting、时光 阅读(473) 评论(0) 推荐(0)
摘要:匈牙利算法(hungary)详解请看http://philoscience.iteye.com/blog/1754498匈牙利算法是用来计算最大匹配,用了增广路思想增广路径有如下特性:1. 有奇数条边2. 起点在二分图的X边,终点在二分图的Y边3. 路径上的点一定是一个在X边,一个在Y边,交错出现。... 阅读全文
posted @ 2015-06-01 21:57 Painting、时光 阅读(803) 评论(0) 推荐(0)
摘要:本文主要是由Wiskey大神的博客的结合少许个人的总结,传送门概念:状态压缩是以二进制来保存每一个的状态,比如总共的物品有n件,那么我一共的状态有2^n次,最大的状态用二进制表示为11....n个1...11,经常得到这样的状态转移方程dp[11001] = dp[10001] + dp[11000... 阅读全文
posted @ 2015-05-13 00:38 Painting、时光 阅读(250) 评论(0) 推荐(0)
摘要:来自杰哥的模板/* 高精度模版 含大数开平方*/#include #include #include #include #include #include using namespace std;const int numlen = 105; // 位数int max(int a, int b... 阅读全文
posted @ 2015-05-08 16:54 Painting、时光 阅读(167) 评论(0) 推荐(1)
摘要:拓扑排序是对ADG(有向无环图进行线性排序)模板:二维数组模拟链表#include#include#include#includeusing namespace std;int indegree[100];queue q;int n,m;bool map[100][100];int a[100];i... 阅读全文
posted @ 2015-05-01 20:26 Painting、时光 阅读(243) 评论(0) 推荐(0)
摘要:找钱问题描述:与背包问题不同,找钱问题是结果必须是把容量全部装满一.用的钱的最大最小数目把空间开大,所需求的dp值只是其中的一种特殊情况而已1.01背包模型,每种货币只能用一次最小求法#include#include#includeusing namespace std;int dp[50000],... 阅读全文
posted @ 2015-05-01 16:06 Painting、时光 阅读(346) 评论(0) 推荐(0)
摘要:算法大意:从一个起点出发,到达所有需要达到的点,再回到本身,求最短路法一:用状态压缩思想#include#include#include#includeusing namespace std;int n;struct edge{ int x; int y;}a[20];int temp[... 阅读全文
posted @ 2015-04-28 15:30 Painting、时光 阅读(186) 评论(0) 推荐(0)
摘要:1.数组模拟链表实现struct edge{ int u,v,w,next;}a[MAX];int E,u,v,w;E = 0;memset(head,-1,sizeof(head));void add(int u,int v,int w){ a[E].u = u;a[E].v = v;... 阅读全文
posted @ 2015-04-28 13:25 Painting、时光 阅读(188) 评论(0) 推荐(0)
摘要:dd大牛的《背包九讲》P01: 01背包问题题目有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。基本思路这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放。用子问题定义状态:即f[i... 阅读全文
posted @ 2015-04-21 20:00 Painting、时光 阅读(383) 评论(0) 推荐(0)
摘要:一 01背包:一件物品只能放一次二维动态转移方程 dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i])降低空间复杂度用一维: dp[j] = max(dp[j],dp[j-w[i]]+v[i]), j 从V到0(为了防止数组越界,到w[i])代码实现:#in... 阅读全文
posted @ 2015-04-21 18:58 Painting、时光 阅读(213) 评论(0) 推荐(0)
摘要:#include #include const int N = 1000000 + 5;char s[N],t[N];int lens,lent;int next[N];void get_fail() { next[0] = -1; for (int i = 1,j = -1; i < ... 阅读全文
posted @ 2015-04-14 21:44 Painting、时光 阅读(146) 评论(0) 推荐(0)