自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(28)
  • 收藏
  • 关注

原创 网络流专题 模板 + 例题 (Going Home POJ - 2195 + Dining   POJ - 3281 )

最大流Dinic 建图时必须要建一条流量为0的反向边#include<bits/stdc++.h>#define ll long long#define MOD 998244353 #define INF 0x3f3f3f3f#define mem(a,x) memset(a,x,sizeof(a)) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);using namespa...

2020-08-03 20:28:25 174

原创 二分图 (最大匹配 + 最小点覆盖 + 最少路径覆盖 + 最大独立集)

最大匹配匈牙利算法。最小点覆盖概念:用最少的点,让每条边都至少和其中的一个点关联König定理:一个二分图中的最大匹配数等于该图的最小顶点覆盖数。最小点覆盖 = 最大匹配。证明:这里最少路径覆盖(不相交路径)概念:在一个有向图中,找出最少的路径,使得这些路径经过其中每个点,且每个点只与一条路径相关联。方法:最少路径覆盖 = 点数 - 二分图最大匹配 。证明:设点数为 n ,最大匹配数为 m,因为我们要让路径尽量少,先设每个点即一条路径,然后一个匹配可以连接两个点,即.

2020-08-03 18:30:40 564

原创 昂贵的聘礼 POJ - 1062 (最短路专题)

题目描述会长东东想娶酋长的女儿,但酋长要求他给一定数额金钱的聘礼。除了金钱外,酋长也允许用部落里其他人的某物品加上一点钱作为聘礼。而其他人的物品也可以通过指定的另外一些人的某物品加上一些金钱获得。但是部落里的每个人有一个等级。整个交易过程涉及的人的等级只能在一个限定的差值内。问会长东东最少需要多少金钱才能娶到酋长女儿。假定每个人只有一个物品。Input输入第一行是两个整数M,N(1 <= N <= 100),依次表示地位等级差距限制和物品的总数。接下来按照编号从小到大依次给出了N个

2020-07-30 22:51:58 266

原创 Cow Contest POJ 3660 (Floyed ) (最短路专题)

题目描述N(1 ≤N≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors.The contest is condu...

2020-07-30 21:24:54 113

原创 B-number HDU - 3652 (数位DP)

题目描述:A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-nu

2020-07-29 00:41:08 127 1

原创 Max Sum Plus Plus HDU - 1024 (DP)

题目描述Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.Given a consecutive number sequence S1, S2, S3, S4... .

2020-07-29 00:01:09 65

原创 You Are the One HDU - 4283 (区间DP)

题目描述 The TV shows such as You Are the One has been very popular. In order to meet the need of boys who are still single, TJUT hold the show itself. The show is hold in the Small hall, so it attract a lot of boys and girls. Now there are n boys enrolling

2020-07-28 23:40:32 139

原创 0 or 1 HDU - 4370 (spfa) 最短路专题

题目描述Given a n*n matrix Cij(1<=i,j<=n),We want to find a n*n matrix Xij(1<=i,j<=n),which is 0 or 1.Besides,Xijmeets the following conditions:1.X12+X13+...X1n=12.X1n+X2n+...Xn-1n=13.for each i (1<i<n), satisfies ∑Xki(1<=k<=...

2020-07-28 00:19:34 154

原创 Trie树模板 + 例题

字典树模板const int maxn=2e6+5;int tree[maxn][55]; //tree[i][j]表示节点i的第j个儿子的节点编号bool flagg[maxn]; //表示以该节点结尾的是一个单词int tot; //总结点数void insert_(char *str){ int len=strlen(str); int root=0; for(int i=0;i<len;i++){ int id=str[i

2020-07-27 22:40:16 105

原创 The Shortest Path in Nya Graph HDU - 4725 分层最短路 Dijkstra(最短路专题)

题目描述Do not sincere non-interference。Like that show, now starvae also take part in a show, but it take place between city A and B. Starvae is in city A and girls are in city B. Every time starvae can get to city B and make a data with a girl he likes. B

2020-07-27 22:23:23 93

原创 Candies (POJ3159) 线性约束差分+堆优化Dijkstra 最短路专题

题目描述During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had flymouse distribute them. All the kids loved candies very much and often compared

2020-07-26 00:03:43 111

原创 Wormholes (POJ 3259)(判断负圈)(spfa) 最短路专题

题目描述While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ's .

2020-07-24 20:27:48 122

原创 Currency Exchange (POJ1860)(判断正圈)(spfa) 最短路专题

题目描述Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be several points specializing in the same pair

2020-07-24 19:10:24 209

原创 PTA L3-020 至多删三个字符 (DP) (天梯赛训练)

题目描述给定一个全部由小写英文字母组成的字符串,允许你至多删掉其中 3 个字符,结果可能有多少种不同的字符串?输入格式:输入在一行中给出全部由小写英文字母组成的、长度在区间 [4,10​6​​] 内的字符串。输出格式:在一行中输出至多删掉其中 3 个字符后不同字符串的个数。思路:用dp[ i ][ j ]表示前 i 个字符中删去 j 个字符时拥有不同字符串的数量。首先不考虑重复的情况,即可以得到转移方程------------------dp[ i ][ j ]=...

2020-07-23 19:30:40 351

原创 Codeforces Round #658 (Div. 2)(D. Unmerge)

题目描述Letaaandbbbe two arrays of lengthsnnandmm, respectively, with no elements in common. We can define a new arraymerge(a,b) of lengthn+mn+mrecursively as follows:If one of the arrays is empty, the result is the other array. That is, merge(∅...

2020-07-23 12:53:19 82

原创 Codeforces Round #656 (Div. 3) (E. Directing Edges)(拓扑排序)

题目描述You are given a graph consisting ofnnvertices andmmedges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some direc...

2020-07-23 12:18:50 85

原创 STL容器 set 使用方法

set 就是集合,可以以log2速度进行查找和插入。set内部是有序的,本质是一颗红黑树(RB树)。使用方法 #include <iostream> #include <set> using namespace std; int main() { set<int> s; s.insert(1); s.insert(2); s.insert(3);...

2020-07-16 10:52:04 117

原创 最短路模板(Floyd+bellman+spfa+Dijkstra)

最短路问题1、单源最短路a、所有权边都是正数: Dijkstra算法 :朴素算法(O(mn)) 堆优化(O(mlogn))b、有负数权变: Bellman算法 : O(mn) Spfa算法:(一般情况O(m),最坏情况 O(mn)) (慎用)2、多源最短路 Floyd算法: O(n^3)Dijkstra#include<bits/stdc++.h>#define ll long l...

2020-07-13 19:48:55 128

原创 Codeforces Round #635 (Div. 2)(D. Xenia and Colorful Gems)(训练)

D. Xenia and Colorful Gems题目大意:给你三个数组a , b , c,在这三个数组中找每个数组找一个数,这三个数为x,y,z, 令ans=(x-y)^2+(y-z)^2+(z-x)^2,求ans的最小值为多少。解题思路: 第一种:最小值一定是三个值最接近的时候,则此时可以考虑在给三个数组进行排序后,用 i , j , k 三个指针进行进行贪心,是最终的最小值一步步逼近即可。 第二种:对数组a进行遍...

2020-07-10 22:46:48 93

原创 Codeforces Round #637 (Div. 2)(D、Nastya and Scoreboard DP、DFS)(训练)

D - Nastya and Scoreboard题意:给你n串由0和1组成的长度为7的字符串,n串表示一个n位数,每个串的第n个位置有1则表示这个位置的火柴是亮着的,位置的表示如下图所示,而每个数字可以由指定位置上的火柴组成,给你每个位上已有火柴的位置,再给你k根火柴,问你由这k根火柴和已有火柴组成的数字,最大是多少。解题思路 :用cnt[ i][ j ]表示第i个字符串要表示为数字j所需要的火柴数量。用DFS进行搜索,运用dp记忆化来去掉很多不需要的情况即可。代码:..

2020-07-09 21:49:22 81

原创 Codeforces Round #639 (Div. 2)(D. Monopole Magnets 题解)(训练)

2020-7-4D. Monopole Magnets英语不好的人真的捉急!!!!!题意:给你n*m的方格,其中有黑格子和白格子,你可以随意乱放S和N。如果N和S在同一行或同一列其中的N将会向S不断移动,在移动过程中N一定不可以出现在白色格子上,并且在所有operation完成后,每行每列必须要有一个S,问你最少需要几个N。解读:1、由于N在移动过程中不能在白色格子上,因此每行每列中由黑色格子组成的线段必须不能在1条以上,否则不存在。 2、如果存在都为白的行,就必须要...

2020-07-05 23:00:58 124

原创 中国剩余定理学习笔记

起源 在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。 解法:1、找出三个数,从3和5的公倍数中找出取余7等于1的数(即15),从3和7的公倍数中找出取余5等于1的数(即21)从5和7的公倍数中找出取余3等于1的数(即70)。 2、用15乘以2(即x...

2020-07-04 10:47:26 151 1

原创 Codeforces Round #638 (Div. 2)(C - Phoenix and Distribution D - Phoenix and Science题解)(训练)

2020-7-3C - Phoenix and Distribution题目大意:给你一个字符串s,将s的所有元素分成k个字符串,让所有字符串按字典序进行排序,问如何让在所有字符串中最大 字符串的字典序最小。解题思路:先对字符串s从小到大进行排序,分类讨论,分两类:1、第k个字符与第1个字符不相等(s[k-1]!=s[0]),则答案就是 s[k-1]。2、第k个字符与第1个字符相等(s[k-1]==s[0]...

2020-07-03 21:23:03 320

原创 Codeforces Round #647 (Div. 2) (D.Johnny and Contribution E.Johnny and Grandmaster 题解)(训练)

D - Johnny and Contribution题目大意 给你m个顶点,n条边的无向图,每个顶点都有自己的期望w[i],将图中所有点填入数字,规则是在填任意一点时,其填入的数字是从1开始且这个点的邻居没有的最小数字,输出填图的顺序。解题思路 首先,将所有期望是1的点全部填入1,将与其有一条边连接的点都填入2,若其中有点的期望值不是2,则说明不存在这种图,即直接退出,输出-1。 ...

2020-07-02 20:17:30 429

原创 三分法+例题(CF1355E - Restorer Distance)

在一个非单调函数中来确定其最值的方法模板整数的三分int l = 1,r = 100;while(l < r) { int lmid = l + (r - l) / 3; int rmid = r - (r - l) / 3; lans = f(lmid),rans = f(rmid); // 求凹函数的极小值 if(lans <= rans) r = rmid - 1; else l = lmid + 1; // 求凸函数

2020-07-01 18:41:53 264

原创 Educational Codeforces Round 81 (Rated for Div. 2)(训练)

A - Display The Number打卡题,只要让位数尽量多(即让1的个数尽量多)代码:#include<bits/stdc++.h>#define ll long long#define maxn 1e5+9#define MOD 1000000007 #define INF 0x3f3f3f3f#define mem(a,x) memset(a,x,sizeof(a)) #define ios ios::sync_with_stdio(false);ci

2020-06-29 23:29:27 134

原创 图的储存---邻接表

存图最基本的方法有两种,分为邻接矩阵和邻接图。一般规模较大的图就是用邻接图来存图。他的优点是存图效率非常高,只需要与边数成正比的空间 存储复杂度为**O(V+E)**,而且能储存重边。 邻接表可以通过结构体+指针,也可以通过结构体+数组,下面介绍结构体+数组的实现。#include<bits/stdc++.h>#define ll long long#define maxn 100005#define MOD 1000000007 #define INF 0x3...

2020-06-28 14:39:50 112

原创 Prime Path(POJ) 3126

https://vjudge.net/problem/POJ-3126题目大意 给你两个四位数,且保证两个数为素数,要从第一个数变为第二个数。在变化过程中,每次只能变化这个数的其中一位且变化后也为素数。求至少需要几次变化。解题思路 首先求出在1000~9999之间的所有素数,存入一个一维数组。建立一个结构体储存当前变化位置中的数和从起点到当前位置的步数。一个自定义...

2020-02-15 22:34:36 136

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除