![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
-----模板题型-----
文章平均质量分 81
wust_zwl
学不死,就往死里学。
展开
-
codeforces 276D Little Girl and Maximum XOR(区间最大异或值--技巧)【模板】
A little girl loves problems on bitwise operations very much. Here's one of them.You are given two integers l and r. Let's consider the values of for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value among all conside原创 2017-10-22 20:45:13 · 574 阅读 · 0 评论 -
POJ 1014 Dividing (多重背包问题+递归)【模板】
Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection原创 2017-08-14 19:52:15 · 587 阅读 · 0 评论 -
HDU 3374 String Problem (KMP+最小最大表示法)【模板】
Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings: String Rank SKYLONG 1 KYLONGS 2 YLONGSK 3 LONGSKY 4 ONGSKYL 5 NGSKYLO 6 GSKYLON 7 and lexicog原创 2017-08-21 20:11:09 · 246 阅读 · 0 评论 -
HDU 3401 Trade(单调队列优化DP)【模板】
Recently, lxhgww is addicted to stock, he finds some regular patterns after a few days' study. He forecasts the next T days' stock market. On the i'th day, you can buy one stock with the price APi or sell one stock to get BPi. There are some other limits原创 2017-08-07 21:03:20 · 411 阅读 · 0 评论 -
POJ 3080 Blue Jeans (KMP+暴力枚举)【模板】
The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated. As an IBM researcher, you have been tasked with writing原创 2017-08-16 21:20:03 · 1205 阅读 · 0 评论 -
HDU 3280 Equal Sum Partitions(区间DP)【模板】
An equal sum partition of a sequence of numbers is a grouping of the numbers (in the same order as the original sequence) in such a way that each group has the same sum. For example, the sequence: 2 5 1 3 3 7 may be grouped as: (2 5) (1 3 3) (7) to yie原创 2017-08-06 19:02:55 · 335 阅读 · 0 评论 -
字符串 最小表示法 O(n)算法 【模板】
Some time the programmers have very strange ways to hide their passwords. See for example how Billy "Hacker" Geits hide his password. Billy chooses a string S composed of small Latin letters with length L. Then he makes all L-1 one-letter left cyclic shift原创 2017-08-21 09:35:19 · 349 阅读 · 0 评论 -
codeforces 182E Wooden Fence(方案数DP)【模板】
Vasya has recently bought some land and decided to surround it with a wooden fence.He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n different t原创 2017-08-14 09:16:32 · 399 阅读 · 0 评论 -
wust oj 1891 低价购买(最长下降子序列+方案数)【模板】
“低价购买”这条建议是在股票市场取得成功的一半规则。要想被认为是伟大的投资者,你必须遵循以下的购买建议:“低价购买;再低价购买”。每次你购买一支股票,你必须用低于你上次购买它的价格购买它。买的次数越多越好!你的目标是在遵循以上建议的前提下,求你最多能购买股票的次数。你将被给出一段时间内一支股票每天的出售价(216范围内的正整数),你可以选择在哪些天购买这支股票。每次购买都必须遵循“低价购买;再低价购买”的原则。写一个程序计算最大购买次数。这里是某支股票的价格清单:日期 1 2 3 4 5 6原创 2017-08-13 10:02:44 · 330 阅读 · 0 评论 -
hdu 1394 Minimum Inversion Number(线段树)【归并排序模板】
归并排序,线段树原创 2017-07-05 22:46:02 · 277 阅读 · 0 评论 -
poj_2478-Farey Sequence(欧拉函数) 【模板】
Language:Farey SequenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16486 Accepted: 6543DescriptionThe Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1原创 2017-07-09 16:29:21 · 286 阅读 · 0 评论 -
HDU 1856 More is better(简单并查集) 【最大并查集人数模板】
Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements. Mr Wang selected a room big enough to hold the boys. The boy who are not been原创 2017-07-10 09:26:50 · 416 阅读 · 0 评论 -
POJ 2082 Terrible Sets(单调栈) 【最大矩形面积类模板】
Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all real numbers. wi, hi for i = 1 . . . n are some elements in N, and w0 = 0. Define set B = {< x, y > | x, y ∈ R and there exists an index i > 0 such that 0 <= y <= hi ,∑原创 2017-07-10 14:50:54 · 234 阅读 · 0 评论 -
POJ 2823 Sliding Window(经典单调队列)
An array of size n ≤ 10 6 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves rightwards by one position. F原创 2017-07-10 22:00:44 · 235 阅读 · 0 评论 -
背包问题--0/1背包 【模板】
首先01背包题目的雏形是有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使价值总和最大。从这个题目中可以看出,01背包的特点就是:每种物品仅有一件,可以选择放或不放。其状态转移方程是:f[i][v]=max{f[i-1][v],f[i-1][v-c[i]]+w[i]}转载 2017-07-11 19:14:58 · 514 阅读 · 0 评论 -
WUST 1872 混合背包 【模板】
一个旅行者有一个最多能用V公斤的背包,现在有n件物品,它们的重量分别是W1,W2,...,Wn,它们的价值分别为C1,C2,...,Cn。有的物品只可以取一次(01背包),有的物品可以取无限次(完全背包),有的物品可以取的次数有一个上限(多重背包)。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。原创 2017-07-12 09:19:47 · 311 阅读 · 0 评论 -
codeforces 5C Longest Regular Bracket Sequence(dp+技巧)【最长连续括号模板】
This is yet another problem dealing with regular bracket sequences.We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and原创 2017-08-11 10:47:34 · 730 阅读 · 0 评论 -
ccpc 2017 网络赛 1004 A Secret (扩展kmp)【模板】
Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which have a big secret.SF is interested in this secret and ask VS how to get it.There are the things that VS tell: Suffix(S2,i) = S2[i...len].Ni is the times that Suffix(S2,i)原创 2017-08-20 17:08:11 · 879 阅读 · 2 评论 -
codeforces 431B Tell Your World(两平行线穿过所有点)【模板】
Connect the countless points with lines, till we reach the faraway yonder.There are n points on a coordinate plane, the i-th of which being (i, yi).Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in原创 2017-09-03 17:08:44 · 736 阅读 · 0 评论 -
SPOJ Balanced Numbers (数位DP+3进制状压)【模板】
Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if:1) Every even digit appears an odd number of times in its decimal representation2) Every odd digit appears an even number o原创 2017-09-03 11:06:03 · 500 阅读 · 0 评论 -
HDU 4507 吉哥系列故事――恨7不成妻 (高级数位DP)【模板】
单身! 依然单身! 吉哥依然单身! DS级码农吉哥依然单身! 所以,他生平最恨情人节,不管是214还是77,他都讨厌! 吉哥观察了214和77这两个数,发现: 2+1+4=7 7+7=7*2 77=7*11 最终,他发现原来这一切归根到底都是因为和7有关!所以,他现在甚至讨厌一切和7有关的数!原创 2017-09-02 21:04:22 · 431 阅读 · 0 评论 -
ZOJ 3805 Machine(搜索+技巧)【树形DP模板】
In a typical assembly line, machines are connected one by one. The first machine's output product will be the second machine's raw material. To simplify the problem, we put all machines into a two-dimension shelf. Every machine occupied exactly one grid an原创 2017-09-01 10:55:07 · 253 阅读 · 0 评论 -
ZOJ 1039 Number Game(SG博弈+状压+记忆化搜索)
BackgroundChristiane and Matthias are playing a new game, the Number Game. The rules of the Number Game are:Christian and Matthias take turns in choosing integer numbers greater than or equal to 2. The following rules restrict the set of numbers which原创 2017-09-01 09:48:52 · 373 阅读 · 0 评论 -
HDU 4336 Card Collector (概率-期望DP)【模板】
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you will win an amazing award. As a smart boy, you notice that to win the a原创 2017-09-07 16:34:51 · 290 阅读 · 0 评论 -
codeforces 182E Wooden Fence(方案数DP)【模板】
Vasya has recently bought some land and decided to surround it with a wooden fence.He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of pro原创 2017-08-14 09:03:29 · 315 阅读 · 0 评论 -
HDU 4405 Aeroplane chess (概率-期望DP)【模板】
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6). When Hzz原创 2017-09-06 20:57:51 · 264 阅读 · 0 评论 -
HDU 3709 Balanced Number (数位DP+思维)【模板】
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. More specifically, imagine each digit as a box with weight indicated by the digit. When a pivot is placed at some digit of the number, the distance from a原创 2017-08-28 15:40:54 · 369 阅读 · 0 评论 -
codeforces 55D Beautiful numbers(数位dp+离散化)【模板】
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers i原创 2017-08-23 14:49:38 · 282 阅读 · 0 评论 -
codeforces 148D Bag of mice (概率DP)【博弈模板】
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to原创 2017-09-05 10:19:22 · 413 阅读 · 0 评论 -
POJ 3744 Scout YYF I (概率DP初涉+矩阵快速幂加速)【模板】
YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's base. After overcoming a series difficulties, YYF is now at the start of enemy's famous "mine road". This is a very long road, on which there are numbers of m原创 2017-09-04 15:35:28 · 271 阅读 · 0 评论 -
POJ 1276 Cash Machine (多重背包+技巧)【标记式背包】
A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the machine has a sup原创 2017-08-15 21:10:21 · 375 阅读 · 0 评论 -
POJ 3253 Fence Repair(STL之优先队列)
Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a single long board j原创 2017-08-22 20:32:17 · 235 阅读 · 0 评论 -
UVA 11375 Matches (dp+高精度)【模板】
We can make digits with matches as shown below:Given N matches, find the number of different numbers representable using the matches. We shallonly make numbers greater than or equal to 0, so no negative signs should be used. For instance, ifyou have 3 ma原创 2017-08-22 19:57:09 · 310 阅读 · 0 评论 -
WUST 1873 潜水员 (二维背包) 【模板】
潜水员为了潜水要使用特殊的装备。他有一个带2种气体的气缸:一个为氧气,一个为氮气。让潜水员下潜的深度需要各种的数量的氧和氮。潜水员有一定数量的气缸。每个气缸都有重量和气体容量。潜水员为了完成他的工作需要特定数量的氧和氮。他完成工作所需气缸的总重的最低限度的是多少? 例如:潜水员有5个气缸。每行三个数字为:氧,氮的(升)量和气缸的重量: 3 36 120 10 25 129 5 50 250 1 45 130 4 20 119 如果潜水员需要5升的氧和6原创 2017-07-12 11:06:48 · 290 阅读 · 0 评论 -
WUST 1874 分组背包 【模板】
一个旅行者有一个最多能用V公斤的背包,现在有n件物品,它们的重量分别是W1,W2,...,Wn,它们的价值分别为C1,C2,...,Cn。这些物品被划分为若干组,每组中的物品互相冲突,最多选一件。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。原创 2017-07-12 14:29:38 · 322 阅读 · 0 评论 -
POJ 1088 滑雪(经典二维动态规划)【模板】
Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑原创 2017-07-12 21:17:44 · 236 阅读 · 0 评论 -
ZOJ 3446 Doraemon's Battle (三维dp+BFS)【打怪类模板】
Doraemon is fighting with n enemies.Doraemon has two properties in this battle, HP and SP. HP is the health point of Doraemon with initial value lh. If Doraemon's HP decreased to 0 or lower, Doraemon will lose the battle. SP is a property for using Dorae原创 2017-08-18 11:05:48 · 305 阅读 · 0 评论 -
codeforces 165E Compatible Numbers(位运算)【模板】
Two integers x and y are compatible, if the result of their bitwise "AND" equals zero, that is, a & b = 0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002 = 02, and numbers 3 (112) and 6 (1102) are not compatible,原创 2017-08-03 20:04:58 · 683 阅读 · 1 评论 -
POJ 1200 Crazy Search(哈希算法)【模板】
Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could be finding a hidden prime number in a given text. Such number could be the number of different substrings of a given size that exist in the text. As you so原创 2017-08-17 20:01:11 · 1055 阅读 · 1 评论 -
codeforces 788A Functions again(dp之最大子段和)【模板】
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximu原创 2017-08-02 16:15:02 · 307 阅读 · 0 评论