
动态规划
文章平均质量分 62
旺 崽
这个作者很懒,什么都没留下…
展开
-
LeetCode 2188 完成比赛的最少时间
给你一个下标从 0 开始的二维整数数组 tires ,其中 tires[i] = [fi, ri] 表示第 i 种轮胎如果连续使用,第 x 圈需要耗时 fi * ri(x-1) 秒。比方说,如果 fi = 3 且 ri = 2 ,且一直使用这种类型的同一条轮胎,那么该轮胎完成第 1 圈赛道耗时 3 秒,完成第 2 圈耗时 3 * 2 = 6 秒,完成第 3 圈耗时 3 * 22 = 12 秒,依次类推。同时给你一个整数 changeTime 和一个整数 numLaps 。比赛总共包含 numLa.原创 2022-05-02 17:52:06 · 453 阅读 · 0 评论 -
2021 年东华大学金马程序设计联赛 K. AEMShana loves games!
题目链接思维+DP~对所有输入样例,我们可以构造出一个等腰三角形,对某一层的顶点,它可以到左上方(在坐标轴上左移一格),正上方(在坐标轴上不动),右上方(在坐标轴上右移一格),那么题目就转化为从顶点走到底部找一条最大路径,非常经典的 DP 问题,用 dp[i][j]dp[i][j]dp[i][j] 表示第 iii 层第 jjj 个点的最大值,a[i][j]a[i][j]a[i][j] 表示拿到该点所有球的得分,则有如下状态转移方程:dp[i][j]=max(dp[i−1][max(j−1,0)],d原创 2021-05-12 15:28:10 · 2051 阅读 · 0 评论 -
LeetCode 1143 最长公共子序列
题目链接给定两个字符串 text1 和 text2,返回这两个字符串的最长公共子序列的长度。如果不存在公共子序列 ,返回 0 。一个字符串的 子序列 是指这样一个新的字符串:它是由原字符串在不改变字符的相对顺序的情况下删除某些字符(也可以不删除任何字符)后组成的新字符串。例如,“ace” 是 “abcde” 的子序列,但 “aec” 不是 “abcde” 的子序列。两个字符串的 公共子序列 是这两个字符串所共同拥有的子序列。示例 1:输入:text1 = "abcde", text2 = "ac原创 2021-04-03 22:09:13 · 1831 阅读 · 0 评论 -
2021牛客寒假算法基础集训营6 E.网格
2021牛客寒假算法基础集训营6 E.网格题目链接题目描述有一个 nnn 行 mmm 列的网格,第 iii 行 jjj 列上有数字 ai,ja_{i,j}ai,j 。每个位置需要从上下左右四个方向中选择互相垂直的两个。定义 w(x)=x+popcnt(x)w(x)=x+popcnt(x)w(x)=x+popcnt(x) ,其中 popcnt(x)popcnt(x)popcnt(x) 表示 x 的二进制位中 1 的位的数量。如果两个相邻的位置 (x1,y1),(x2,y2)(x_1,y_1),(x原创 2021-02-25 19:52:24 · 2026 阅读 · 0 评论 -
牛客2020跨年场 B.牛牛想起飞
牛客2020跨年场 B.牛牛想起飞题目链接题目描述给定一个长度为 nnn 的序列 aaa 和一个长度为 nnn 的序列 bbb,对于序列中的每一个数字 aia_iai,牛牛都可以进行以下操作:(1) 将数字 aia_iai 从 aia_iai 变成 ai+bia_i + b_iai+bi;(2) 将数字 aia_iai 从 aia_iai 变成 ai−bia_i - b_iai−bi。牛牛很懒,所以每个数字只能最多进行一次操作,甚至不操作。现在给出一个数字 y ,牛牛想要知道在原创 2021-01-16 10:56:43 · 2204 阅读 · 0 评论 -
LeetCode 1696 跳跃游戏 VI
LeetCode 1696 跳跃游戏 VI题目链接给你一个下标从 000 开始的整数数组 numsnumsnums 和一个整数 kkk 。一开始你在下标 000 处。每一步,你最多可以往前跳 kkk 步,但你不能跳出数组的边界。也就是说,你可以从下标 iii 跳到 [i+1,min(n−1,i+k)][i + 1, min(n - 1, i + k)][i+1,min(n−1,i+k)] 包含 两个端点的任意位置。你的目标是到达数组最后一个位置(下标为 n−1n - 1n−1 ),你的 得分 为经过原创 2020-12-25 10:14:59 · 2448 阅读 · 0 评论 -
AtCoder Beginner Contest 183 E.Queen on Grid
AtCoder Beginner Contest 183 E.Queen on Grid题目链接典型的 DP~如果我们考虑暴力,每个点的答案就是该点往左所有的可行点的答案+往上所有可行点的答案+往左上角的对角线上所有可行点的答案,这样复杂度为 O(N3)O(N^3)O(N3),显然不可取,如果要让复杂度降到 O(N2)O(N^2)O(N2),就必须要求出三个方向可行点的前缀和,于是我们可以在计算每个点的同时,往它的下方的一个点,右方的一个点和右下方的一个点传递答案,这样就相当于求了一个前缀和,若分别原创 2020-11-17 19:13:46 · 2398 阅读 · 0 评论 -
Codeforces Round #674 (Div. 3) F. Number of Subsequences
Codeforces Round #674 (Div. 3) F. Number of Subsequences题目链接You are given a string s consisting of lowercase Latin letters “a”, “b” and “c” and question marks “?”.Let the number of question marks in the string s be k. Let’s replace each question mark wi原创 2020-10-05 11:09:43 · 3294 阅读 · 0 评论 -
剑指 Offer 46 把数字翻译成字符串
剑指 Offer 46 把数字翻译成字符串题目链接给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 “a” ,1 翻译成 “b”,……,11 翻译成 “l”,……,25 翻译成 “z”。一个数字可能有多个翻译。请编程实现一个函数,用来计算一个数字有多少种不同的翻译方法。示例 1:输入:12258输出:5典型的 DP~我们用 dp[i]dp[i]dp[i] 记录前 iii 个数的最多翻译方法,对当前位置 iii,有如下的状态转移方程:dp[i]+=dp[i−1]dp[i]+=原创 2020-09-22 19:23:37 · 2396 阅读 · 0 评论 -
Educational Codeforces Round 93 (Rated for Div. 2) C. Good Subarrays
Educational Codeforces Round 93 (Rated for Div. 2) C. Good Subarrays题目链接You are given an array a1,a2,…,an consisting of integers from 0 to 9. A subarray al,al+1,al+2,…,ar−1,ar is good if the sum of elements of this subarray is equal to the length of this原创 2020-09-11 21:31:46 · 2501 阅读 · 2 评论 -
HDUOJ 6570 Wave
HDOUJ 6570 Wave题目链接 Problem DescriptionAvin is studying series. A series is called “wave” if the following conditions are satisfied:1) It contains at least two elements;2) All elements at odd positions are the same;3) All elements at even positions a原创 2020-09-11 11:32:14 · 2477 阅读 · 0 评论 -
牛客 13134 牛牛的数列
牛客 13134 牛牛的数列题目链接题目描述给你一个长度为50的数字串,问你有多少个子序列构成的数字可以被3整除答案对1e9+7取模输入描述:输入一个字符串,由数字构成,长度小于等于50输出描述:输出一个整数示例1输入132输出3示例2输入9输出1示例3输入333输出7简单 DP,AC代码如下:#include <bits/stdc++.h>using namespace std;const int mod=1e9+7;int原创 2020-09-08 19:47:25 · 2475 阅读 · 0 评论 -
HHUOJ 1094 ZHAN 与糖果
HHUOJ 1094 ZHAN 与糖果题目链接题目描述ZHAN 很喜欢吃糖果。一天,huahua 刚从超市买到一大包糖果,结账出门转角遇到 ZHAN,他紧盯着 huahua 手里的糖果,可 怜的目光使 huahua 停下了脚步。huahua 决定出一个问题,如果 ZHAN 能答对就分一些糖果给他。假设 huahua 手里有 n 颗糖果,每颗糖果具有自己的快乐值 ai (1 ≤ i ≤ n),如果 ZHAN 吃掉第 i 颗糖果, 他会获得糖果对应的快乐值。当 ZHAN 获得的快乐值之和是 m 的倍数原创 2020-09-06 15:32:54 · 2489 阅读 · 0 评论 -
AtCoder Beginner Contest 175 E.Picking Goods
AtCoder Beginner Contest 175 E.Picking Goods题目链接典型的 DP,如果不加限制条件的话就是从上到下找一条最长路,但是限制了每行只能选 3 个,所以就多加一维,状态转移方程为:dp[i][j][k]=max(dp[i−1][j][3]+g[i][j],max(dp[i][j−1][k−1]+g[i][j],dp[i][j−1][k]))dp[i][j][k]=max(dp[i-1][j][3]+g[i][j],max(dp[i][j-1][k-1]+g[i]原创 2020-09-04 18:24:40 · 2489 阅读 · 0 评论 -
牛客小白月赛27 B.乐团派对
牛客小白月赛27 B.乐团派对题目链接题目描述音乐是带给大家快乐的存在,而你的目标就是组建若干支乐队,让世界听到你们的演奏!你目前有 nnn 位乐手,每位乐手只能进入一个乐队,但并不是每位乐手都能担大任,因此需要团队合作。第ii位乐手的能力值为 a[i]a[i]a[i],表示该位乐手所在乐队的人数必须大于等于 a[i]a[i]a[i]。在保证每位乐手都被分进一个乐队的情况下,乐队数量最多可以是多少?输入描述:第一行一个正整数 nnn,表示乐手人数,n≤105n\leq10^{5}n≤105。第原创 2020-08-23 19:52:36 · 2448 阅读 · 0 评论 -
牛客小白月赛3 B.躲藏
牛客小白月赛3 B.躲藏题目链接题目描述XHRlyb和她的小伙伴Cwbc在玩捉迷藏游戏。Cwbc藏在多个不区分大小写的字符串中。好奇的XHRlyb想知道,在每个字符串中Cwbc作为子序列分别出现了多少次。由于Cwbc可能出现的次数过多,你只需要输出每个答案对 200012042001012220001204200101222000120420010122 取模后的结果。聪明的你在仔细阅读题目后,一定可以顺利的解决这个问题!输入描述:输入数据有多行,每行有一个字符串。输出描述:输出数据应原创 2020-08-16 17:24:24 · 2468 阅读 · 0 评论 -
牛客练习赛67 D.牛妹爱数列
牛客练习赛67 D.牛妹爱数列题目链接题目描述牛妹正在玩一个数列他手里有一个长度为n的序列a,保证它是一个01序列,并执行以下两种操作:1.单点修改:将位置x上的数翻转(0变1,1变0);2.前缀修改:将位置1~x上的数翻转(每个数都0变1,1变0)。他现在想要最小化翻转次数,使得数列上的所有数都变为0。输入描述:第一行,输入一个数 nnn。第二行,输入 nnn 个数,第i个数表示 aia_iai。输出描述:输出最小翻转次数。示例1输入101 0 1 1 0 0 0 1 0原创 2020-08-15 19:16:25 · 2494 阅读 · 2 评论 -
牛客小白月赛1 G .あなたの蛙は旅⽴っています
牛客小白月赛1 G .あなたの蛙は旅⽴っています题目链接题目描述あなたの蛙は旅立っています!你的蛙正在考虑它应该按怎样的路线去旅行。这些景点可以抽象为 NNN 个镶嵌着的六边形。每个景点 iii 都有一个快乐度 HiH_iHi。蛙蛙想要决定一条路线,使得路线上的景点快乐度之和最大。而你的蛙蛙又是一只不走回头路的蛙,所以它每次只能朝远处走。比如,上图就是一个例子。蛙蛙会从最上方的黄色六边形出发,每次只能走到下方的直接相邻的三个六边形中(边界上可能只有一个或两个直接相邻的六边形),这样一直走到最原创 2020-08-12 17:38:43 · 2432 阅读 · 0 评论 -
HDUOJ 6806 Equal Sentences
HDUOJ 6806 Equal Sentences题目链接Problem DescriptionSometimes, changing the order of the words in a sentence doesn’t influence understanding. For example, if we change “what time is it”, into “what time it is”; or change “orz zhang three ak world final”, i原创 2020-08-02 18:50:38 · 2364 阅读 · 0 评论 -
HDUOJ 6787 Chess
HDUOJ 6787 Chess题目链接Problem Description你现在有一个棋盘,上面有 n 个格子,格子从左往右,1,…,n 进行标号。你可以在棋盘上放置恰好 m 个传送器,并且对于每个传送器设置传送位置。传送位置需满足:对于在 i 号格子上的传送器,传送目标位置 j 满足 j<i。1 号格子不能放置传送器。现在有一名玩家,拿着一枚 1,…,11 的骰子(骰子每次等概率地投出 1 到 11 中的一个数字),从位置 1 开始,用骰子决定前进步数,即如果当前在位置 y 且投出数原创 2020-07-28 18:16:38 · 2379 阅读 · 0 评论 -
2020牛客暑期多校训练营(第三场)E.Two Matchings
2020牛客暑期多校训练营(第三场)E.Two Matchings题目链接题目描述A permutation of length n is an array p=[p1,p2,…,pn]p=[p_1, p_2, \ldots, p_n]p=[p1,p2,…,pn], which contains every integer from 1 to n (inclusive) and each number appears exactly once. For example, p=[3,1,4,6,2原创 2020-07-22 20:08:45 · 2422 阅读 · 0 评论 -
洛谷 P1725 琪露诺
洛谷 P1725 琪露诺题目链接题目描述在幻想乡,琪露诺是以笨蛋闻名的冰之妖精。某一天,琪露诺又在玩速冻青蛙,就是用冰把青蛙瞬间冻起来。但是这只青蛙比以往的要聪明许多,在琪露诺来之前就已经跑到了河的对岸。于是琪露诺决定到河岸去追青蛙。小河可以看作一列格子依次编号为0到N,琪露诺只能从编号小的格子移动到编号大的格子。而且琪露诺按照一种特殊的方式进行移动,当她在格子i时,她只移动到区间[i+l,i+r]中的任意一格。你问为什么她这么移动,这还不简单,因为她是笨蛋啊。每一个格子都有一个冰冻指数A[i]原创 2020-12-25 11:38:54 · 2720 阅读 · 0 评论 -
POJ 3264 Balanced Lineup
POJ 3264 Balanced Lineup题目链接DescriptionFor the daily milking, Farmer John’s N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he wil原创 2020-07-05 18:38:53 · 2443 阅读 · 0 评论 -
HDUOJ 2859 Phalanx
HDUOJ 2859 Phalanx题目链接Problem DescriptionToday is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anniversary of the PRC.A phalanx is a matrix of size n∗nn*nn∗n, each element is a character (a~z or A~Z), standing原创 2020-07-05 16:29:41 · 2434 阅读 · 0 评论 -
HDUOJ 1078 FatMouse and Cheese
HDUOJ 1078 FatMouse and Cheese题目链接Problem DescriptionFatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid lo原创 2020-07-05 10:04:28 · 2356 阅读 · 0 评论 -
HDUOJ 1260 Tickets
HDUOJ 1260 Tickets题目链接Problem DescriptionJesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.A原创 2020-07-04 16:33:04 · 2307 阅读 · 0 评论 -
HDUOJ 1565 方格取数(1)
HDUOJ 1565 方格取数(1)题目链接Problem Description给你一个n*n的格子的棋盘,每个格子里面有一个非负数。从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和最大。Input包括多个测试实例,每个测试实例包括一个整数 n 和 n*n个非负数(n<=20)Output对于每个测试实例,输出可能取得的最大的和Sample Input375 15 21 75 15 28 34 70 5 Sa原创 2020-07-01 17:05:49 · 2610 阅读 · 0 评论 -
HDUOJ 1087 Super Jumping! Jumping! Jumping!
HDUOJ 1087 Super Jumping! Jumping! Jumping!题目链接Problem DescriptionNowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.原创 2020-07-01 15:55:56 · 2415 阅读 · 0 评论 -
HDUOJ 1069 Monkey and Banana
HDUOJ 1069 Monkey and Banana题目链接Problem DescriptionA group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey原创 2020-07-01 10:27:02 · 2481 阅读 · 0 评论 -
HDUOJ 1024 Max Sum Plus Plus
HDUOJ 1024 Max Sum Plus Plus题目链接Problem DescriptionNow 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原创 2020-06-30 16:18:10 · 2329 阅读 · 0 评论 -
计蒜客 T1408 矩形嵌套
计蒜客 T1408 矩形嵌套题目链接有 n 个矩形,每个矩形可以用 a,b 来描述,表示长和宽。矩形 X(a,b) 可以嵌套在矩形 Y(c,d) 中当且仅当 a<c,b<d 或者 b<c,a<d(相当于旋转 9090 度)。例如(1,5)可以嵌套在(6,2)内,但不能嵌套在(3,4)中。你的任务是选出尽可能多的矩形排成一行,使得除最后一个外,每一个矩形都可以嵌套在下一个矩形内。输入格式第一行是一个正数 N(0<N<10),表示测试数据组数。每组测试数据的第一行是原创 2020-06-29 16:41:42 · 2528 阅读 · 0 评论 -
2019牛客暑期多校训练营(第四场)J.free
2019牛客暑期多校训练营(第四场)J.free题目链接题目描述Your are given an undirect connected graph.Every edge has a cost to pass.You should choose a path from S to T and you need to pay for all the edges in your path. However, you can choose at most k edges in the graph and ch原创 2020-06-28 15:46:42 · 2442 阅读 · 0 评论 -
The Preliminary Contest for ICPC Asia Shanghai 2019 J. Stone game
The Preliminary Contest for ICPC Asia Shanghai 2019 J. Stone game题目链接CSL loves stone games. He has nn stones; each has a weight aia_iai. CSL wants to get some stones. The rule is that the pile he gets should have a higher or equal total weight than the原创 2020-06-25 20:16:15 · 2356 阅读 · 0 评论 -
2019牛客暑期多校训练营(第四场)K.number
2019牛客暑期多校训练营(第四场)K.number题目链接题目描述300iq loves numbers who are multiple of 300.One day he got a string consisted of numbers. He wants to know how many substrings in the string are multiples of 300 when considered as decimal integers.Note that leading a原创 2020-06-25 19:50:32 · 2332 阅读 · 0 评论 -
2019牛客暑期多校训练营(第二场)H.Second Large Rectangle
2019牛客暑期多校训练营(第二场)H.Second Large Rectangle题目链接题目描述Given a N×MN \times MN×Mbinary matrix. Please output the size of second large rectangle containing all "1"\texttt{"1"}"1".Containing all "1"\texttt{"1"}"1" means that the entries of the rectangle are al原创 2020-06-19 15:20:38 · 2344 阅读 · 0 评论 -
AtCoder Beginner Contest 169 F.Knapsack for All Subsets
AtCoder Beginner Contest 169 F.Knapsack for All Subsets题目链接又是魔性 dpdpdp,大佬总是两百行解决,膜了????用 dp[i]dp[i]dp[i] 表示结果,对每个 a,i∈[s,0]a,i∈[s,0]a,i∈[s,0],可以得到状态转移方程:dp[i+a]=dp[i+a]+dp[i]dp[i+a]=dp[i+a]+dp[i]dp[i+a]=dp[i+a]+dp[i]dp[i]=dp[i]∗2dp[i]=dp[i]*2dp[i]=dp原创 2020-06-09 10:23:52 · 2422 阅读 · 0 评论 -
东华大学2020年程序设计竞赛(同步赛)G.Gaming with Mia
东华大学2020年程序设计竞赛(同步赛)G.Gaming with Mia题目链接题目描述Mia is learning data structures, this semester. After her boyfriend, John, has given so many problems to her, this time, Mia gives John an interesting problem, or rather, an intellectual game.In this problem原创 2020-06-08 14:10:28 · 2488 阅读 · 0 评论 -
Codeforces Round #641 (Div. 2) B.Orac and Models
Codeforces Round #641 (Div. 2) B.Orac and Models题目链接There are n models in the shop numbered from 1 to n, with sizes s1,s2,…,sn.Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).Orac原创 2020-05-13 18:03:52 · 2340 阅读 · 0 评论 -
AtCoder Beginner Contest 165 F.LIS on Tree
AtCoder Beginner Contest 165 F.LIS on Tree题目链接典型的树上 dpdpdp 问题通过 DFS + DP 求得每个点的最大值,然后回溯记录答案即可,AC代码如下:#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e5+5;in...原创 2020-05-06 09:48:45 · 2333 阅读 · 0 评论 -
AtCoder Beginner Contest 166 E.This Message Will Self-Destruct in 5s
AtCoder Beginner Contest 166 E.This Message Will Self-Destruct in 5s题目链接思维题,题意是找一对 (i,j)(i,j)(i,j) 使得 ai+aj=j−ia_i+a_j=j-iai+aj=j−i,我们不妨设 i<ji<ji<j,移项得:aj−j=−ai−ia_j-j=-a_i-iaj−j=−ai−i...原创 2020-05-04 16:57:55 · 2387 阅读 · 0 评论