DP
文章平均质量分 80
丿残念灬
这个作者很懒,什么都没留下…
展开
-
POJ-3356 AGTC(编辑距离)
AGTCTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 12609 Accepted: 4748DescriptionLet x and y be two strings over some finite alphabet A. We would li原创 2016-08-15 22:50:25 · 274 阅读 · 0 评论 -
HDU-6065 RXD, tree and sequence(dp+LCA)
传送门:HDU-6065题意:根节点为1的有根树,给定一个排列,长度为n,要求将排列切分成K段,定义每段的价值为该排列中两两之间的公共祖先中的最浅深度。要求总价值最小题解:首先列出几个性质:性质1.所有节点的公共祖先的深度一定是两两节点之间的公共祖先的最浅深度性质2.如果某一段的前x个数的公共祖先为rt,那么加入第x+1个树后,公共祖先的深度是LCA(rt,a[x+1])证原创 2017-08-04 23:20:08 · 935 阅读 · 0 评论 -
Codeforces-822D Winter is here(DP)
D. Winter is heretime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWinter is here at the North and the White原创 2017-08-21 16:52:16 · 270 阅读 · 0 评论 -
Codeforces-840C On the Bench(dp)
C. On the Benchtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA year ago on the bench in public park Leha found an array of ...原创 2017-08-22 21:30:01 · 1437 阅读 · 0 评论 -
Codeforces-830D Singer House(组合数+dp)
D. Singer Housetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt is known that passages in Singer house a原创 2017-08-27 16:04:44 · 617 阅读 · 0 评论 -
Codeforces-813D Two Melodies(dp)
D. Two Melodiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice is a beginner composer and now she is原创 2017-08-29 10:00:02 · 551 阅读 · 0 评论 -
Codeforces-821E Okabe and El Psy Kongroo(矩阵快速幂+dp)
传送门:CF-821E#include #define x first#define y secondusing namespace std;typedef long long LL;const LL mod = 1e9 + 7;int sz;struct Mat { LL x[16][16]; Mat() { memset(x, 0, sizeo原创 2017-08-30 14:59:23 · 321 阅读 · 0 评论 -
Codeforces-814E An unavoidable detour for home(DP)
传送门:CF-814E题意:给出n个点每个点的度数为2或3,对于第i个点和第i+1个点,第i个点到第一个点的最短距离不能大于第i+1个点到第一个点的最短距离,问有多少种建图的方法根据题意有2个性质:①有边连接的两个点的深度差不超过1,否则bfs中根到某个节点的距离就不是最短路②深度相同的点,编号一定是连续的状态转移时,只考虑当前层和上一层的设f[i][j]为一共有i个点原创 2017-08-30 15:03:20 · 1470 阅读 · 2 评论 -
Codeforces-869C The Intriguing Obsession(DP/组合数)
传送门:CF-869C题意:有3个集合,其中元素分别有a、b、c个,且元素之间各不相同,元素之间可以连一条边,连边后相同集合的元素之间的距离不能小于3(当然相同集合的元素之间不能连边),问连边的方案数题解:首先只考虑2个集合的情况:dp[i][j]:集合A,B的元素分别有i个和j个时的方案数向集合A新增一个元素时(设这一个元素为i),如果i不与任何点连线,则方案数为dp[i][原创 2017-10-18 01:10:57 · 486 阅读 · 0 评论 -
GYM-101572A Airport Coffee(DP+单调队列)
题意:一个人要从起点走到终点,距离为m,速度为A中间有n个咖啡馆,当经过咖啡馆可以选择买咖啡,买完咖啡后需要经过T秒的冷却,冷却期间这个人的速度为A,接着花R秒喝咖啡,喝咖啡期间速度变成B(B>A),每次经过咖啡馆如果要买新咖啡就需要把原本的扔掉。问:如果要用最短的时间到达终点,买咖啡的方案是怎样,输出任意一个方案题解:设dp[i]为到达第i个咖啡馆并买咖啡原创 2017-12-10 00:06:47 · 378 阅读 · 0 评论 -
Codeforces-903F Clear The Matrix(状压DP)
F. Clear The Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a matrix f with 4 rows a原创 2017-12-13 21:06:44 · 931 阅读 · 0 评论 -
Codeforces-Avito Code Challenge 2018-E Addition on Segments(DP)
传送门:戳这里 题解:将m次修改按R升序排序,dp[i]保存当i为最大值时,i的最右下标,由于R是升序的,只要i的最右下标不小于L就能修改,变成i+x#include<bits/stdc++.h>using namespace std;const int MX = 1e4 + 5;struct node { int l, r, x; bool ope...原创 2018-05-28 21:19:05 · 238 阅读 · 0 评论 -
Nowcoder-2018ACM多校训练营(第四场)B Interval Revisited
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 131072K,其他语言262144K64bit IO Format: %lld题目描述 Chiaki has a long interval [1,m] and n small intervals [l1, r1], [l2,r2], ..., [ln, rn]. Each small interval [li,ri] i...原创 2018-07-29 13:07:04 · 258 阅读 · 0 评论 -
CodeForces-712D Memory and Scores(计数)
D. Memory and Scorestime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMemory and his friend Lexa are competing to get higher score...原创 2018-07-28 10:20:58 · 168 阅读 · 0 评论 -
HDU-6357 Hills And Valleys(DP)
Hills And ValleysTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 146 Accepted Submission(s): 47Special Judge Problem DescriptionTau...原创 2018-08-06 22:25:23 · 344 阅读 · 0 评论 -
HDU-6407 Pop the Balloons(DP)
Pop the BalloonsTime Limit: 7000/7000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 87 Accepted Submission(s): 27 Problem DescriptionRecently, an inter...原创 2018-08-15 23:20:44 · 776 阅读 · 0 评论 -
HDU-5932 Backpack on Tree(DP+贪心)
Backpack on TreeTime Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 193 Accepted Submission(s): 54 Problem DescriptionThere is a rooted t...原创 2018-08-23 12:41:08 · 233 阅读 · 0 评论 -
CodeForces-H Path Counting(DP)
H. Path Countingtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree. Let's denote d(x) as depth of node ...原创 2018-09-06 18:56:07 · 272 阅读 · 0 评论 -
Codeforces-837D Round Subset(dp)
D. Round Subsettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call the roundness of the number the原创 2017-08-04 13:17:22 · 767 阅读 · 0 评论 -
HDU-6078 Wavel Sequence(dp+树状数组)
传送门:HDU-6070题意:有2个序列A和B,要从A,B中选子序列出来组成“小-大-小”这样的序列,且A,B对应的位置要相等,问有多少种选取方法题解:dp+树状数组设f[x][y][k]为当前A数组枚举到第x个,B数组枚举到第y个,起伏状态为k(0/1)时的方案数,考虑到用普通的dp转移会达到O(n^4),可以用二维树状数组进行维护,由于第一维具有递增的特性,因此只要维护第二维的下标原创 2017-08-03 22:30:17 · 893 阅读 · 0 评论 -
CodeForces-505C Mr. Kitayuta, the Treasure Hunter
Mr. Kitayuta, the Treasure Huntertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Shuseki Islands are an原创 2016-08-16 10:20:13 · 537 阅读 · 0 评论 -
CSU-1804 有向无环图(拓扑排序+dp)(湖南省第十二届大学生程序设计竞赛)
1804: 有向无环图Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 205 Solved: 90[Submit][Status][Web Board]DescriptionBobo 有一个 n 个点,m 条边的有向无环图(即对于任意点 v,不存在从点 v 开始、点 v 结束的路径)。为了方便,点用 1,2,…,n原创 2016-09-04 20:58:42 · 506 阅读 · 0 评论 -
CodeForces-710E Generate a String(DP)
E. Generate a Stringtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputzscoder wants to generate an input fil原创 2016-09-05 00:16:35 · 356 阅读 · 0 评论 -
HDU-5119 Happy Matt Friends(背包)
Happy Matt FriendsTime Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Others)Total Submission(s): 3341 Accepted Submission(s): 1301Problem DescriptionMatt原创 2016-11-03 22:53:40 · 349 阅读 · 0 评论 -
codeForces-743E Vladik and cards(状压+记忆化搜索+二分)
传送门:http://codeforces.com/contest/743/problem/E题意:有n个元素的序列,每个元素均是[1,8]中的整数,要求找出他的最长子序列满足以下2个条件:①在这个序列中,[1,8]每个数字出现的次数之差的绝对值不超过1;②相同的数字必须连续.输出最长子序列的长度题解:①对于每种数字保存他出现时的下标;②二分每种数字至少出现x次,因此每种元素可能出现的次数原创 2016-12-16 21:16:49 · 627 阅读 · 0 评论 -
HDU-5256 序列变换(LIS)
序列变换Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1454 Accepted Submission(s): 540Problem Description我们有一个数列A1,A2...An,你现在要求修改数原创 2016-08-13 17:46:33 · 651 阅读 · 0 评论 -
HDU-5495 LCS(最长公共子序列)
LCSTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 801 Accepted Submission(s): 443Problem DescriptionYou are given two sequence原创 2016-08-12 21:43:52 · 1015 阅读 · 0 评论 -
CSU-1835 Pry Sequence Transformation(DP)
1835: Pry Sequence TransformationSubmit Page Summary Time Limit: 2 Sec Memory Limit: 128 Mb Submitted: 90 Solved: 22 DescriptionHaving solved the edit distan原创 2017-03-21 18:10:36 · 485 阅读 · 0 评论 -
Codeforces-788A Functions again(dp)
A. Functions againtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSomething happened in Uzhlyandia again...原创 2017-03-31 23:35:33 · 1029 阅读 · 0 评论 -
WOJ-29 Werewolf(DP)
Input file: standard inputOutput file: standard output Time limit: 1 secondMemory limit: 512 mebibytesGenerally, ACMers play Werewolf game anywhere when they go out for any programming contest原创 2017-04-11 16:31:18 · 543 阅读 · 0 评论 -
xtu-1269 Similar Subsequence(dp+树状数组)
Similar SubsequenceAccepted : 17 Submit : 73Time Limit : 10000 MS Memory Limit : 135536 KBSimilar SubsequenceFor given sequence A=(a 1 ,a 2 ,…,a n ) , a原创 2017-05-17 21:38:26 · 414 阅读 · 0 评论 -
hihocoder-1526 序列的值(DP/二进制)
#1526 : 序列的值时间限制:20000ms单点时限:1000ms内存限制:256MB描述给定一个长度为 n 的序列 a[1..n],定义函数 f(b[1..m]) 的值为在 [0,m-1] 内满足如下条件的 i 的数目:b 中前 i 个数异或起来的值小于 b 中前 i +1个数异或起来的值。对于 a[1..n] 的每个子序列原创 2017-07-11 14:29:43 · 402 阅读 · 0 评论 -
HDU-5981 Guess the number(DP)
Guess the number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 160000/160000 K (Java/Others)Total Submission(s): 245 Accepted Submission(s): 99 Problem DescriptionAOA just m...原创 2017-07-17 15:04:54 · 1676 阅读 · 2 评论 -
Gym-100820 Racing Gems(二维LIS)
传送门:http://codeforces.com/gym/100820/attachments#includeusing namespace std;typedef long long LL;const int MX = 1e5 + 5;struct node{ LL a,b;}p[MX];bool cmp(node p1,node p2){ if(p1.a!=p原创 2017-07-22 21:25:18 · 355 阅读 · 0 评论 -
Codeforces-834D The Bakery(线段树+dp)
传送门:Codeforces-834D设w(l,r)为[l,r]之间不同数字的个数于是有:f[i][j]=max(f[k][j-1]+w(k+1,i)) k∈[1,i-1]我们可以建立线段树对其进行维护:建立一棵关于f[i][j-1]的线段树,f[i][j-1]=Query(0,i-1)现在要将系列分成j份,w(k+1,i)相当于将[k+1,i]区间内的数对f[i][j]的贡献,将原创 2017-08-01 11:12:59 · 709 阅读 · 0 评论 -
HDU-6092 Rikka with Subset(dp)
传送门:HDU-6092这道题就是个01背包的逆过程,B[i]+=B[i-Aj]#includeusing namespace std;typedef long long LL;const int MX = 1e4 + 5;const int inf = 0x3f3f3f3f;int dp[MX];int main() { int T,n,m; //freop原创 2017-08-09 14:43:26 · 352 阅读 · 0 评论 -
2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest K Knights of the Old Republic(贪心+DP)
传送门:戳这里将边按从小到大排序,模拟Kruskal,设当前要合并的2个集合为x和y设要占领当前这条边,需要花费w①如果要占领这条边,则花费为min(b[v]) * max(w, max(a[u])),其中u和v是集合x和y中的点②如果不占领这条边,则花费为f[x] + f[y]#include<bits/stdc++.h>#define lson l,m,rt<...原创 2018-12-04 16:11:14 · 560 阅读 · 0 评论