动态规划
文章平均质量分 60
Scare-Crow
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
For Gamers. By Gamers. dp(倍数)
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp hasCCcoins to spend on his squad.Before each battle starts, his squad is empty. Monocarp choosesone type of unitsand recruits no mor...原创 2022-03-23 21:59:41 · 766 阅读 · 0 评论 -
Leaf Partition 树形dp 思维
You are given a rooted tree withnnnodes, labeled from11tonn. The tree is rooted at node11. The parent of theii-th node ispipi. A leaf is node with no children. For a given set of leavesLL, letf(L)f(L)denote the smallest connected subgraph that c...原创 2022-03-19 08:58:25 · 300 阅读 · 0 评论 -
Edge Groups 思维 树形dp
Given an undirected connected graph ofnnvertices andn−1n−1edges, wherennis guaranteed to be odd. You want to divide all then−1n−1edges ton−12n−12groups under following constraints:There are exactly 2 edges in each group The 2 edges in the same...原创 2022-03-16 19:16:39 · 997 阅读 · 0 评论 -
Arena dp 逆序思维
There arennheroes fighting in the arena. Initially, theii-th hero hasa_iaihealth points.The fight in the arena takes place in several rounds. At the beginning of each round, each alive hero deals11damage to all other heroes. Hits of all heroes oc...原创 2022-03-14 17:04:24 · 450 阅读 · 0 评论 -
Zero Remainder Sum dp(模数)
You are given a matrixaaof sizen \times mn×mconsisting of integers.You can chooseno more than\left\lfloor\frac{m}{2}\right\rfloor⌊2m⌋elements ineach row. Your task is to choose these elements in such a way that their sum isdivisible bykkand t...原创 2022-03-14 16:54:27 · 294 阅读 · 0 评论 -
Road Optimization 线性dp
The Government of Mars is not only interested in optimizing space flights, but also wants to improve the road system of the planet.One of the most important highways of Mars connects Olymp City and Kstolop, the capital of Cydonia. In this problem, we onl原创 2022-03-13 22:36:59 · 400 阅读 · 0 评论 -
Gas Pipeline 线性dp
You are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment[0,n][0,n]onOXOXaxis. The road can have several crossroads, but for simplicity, we'll denote each crossroad as an interval(x,x+1)(x,x+...原创 2022-03-13 22:32:23 · 544 阅读 · 0 评论 -
数字游戏 数位dp
科协里最近很流行数字游戏。某人命名了一种不降数,这种数字必须满足从左到右各位数字成小于等于的关系,如123123,446446。现在大家决定玩一个游戏,指定一个整数闭区间[a,b][a,b],问这个区间内有多少个不降数。输入格式有多组测试数据。每组只含两个数字a,ba,b,意义如题目描述。输出格式每行给出一个测试数据的答案,即[a, b][a,b]之间有多少不降数。样例Inputcopy Outputcopy 1 91 19 9...原创 2022-03-07 19:57:59 · 4040 阅读 · 0 评论 -
洛谷P2657 windy 数 数位dp
题目背景windy 定义了一种 windy 数。题目描述不含前导零且相邻两个数字之差至少为2的正整数被称为 windy 数。windy 想知道,在a和b之间,包括a和b,总共有多少个 windy 数?输入格式输入只有一行两个整数,分别表示 a和 b。输出格式输出一行一个整数表示答案。输入输出样例输入 #1复制1 10输出 #1复制9输入 #2复制25 50输出 #2复制20说明/提示数据规模与约定对...原创 2022-03-02 20:09:21 · 379 阅读 · 0 评论 -
洛谷P2704 炮兵阵地 状压dp
题目描述司令部的将军们打算在N\times MN×M的网格地图上部署他们的炮兵部队。一个N\times MN×M的地图由NN行MM列组成,地图的每一格可能是山地(用\texttt{H}H表示),也可能是平原(用\texttt{P}P表示),如下图。在每一格平原地形上最多可以布置一支炮兵部队(山地上不能够部署炮兵部队);一支炮兵部队在地图上的攻击范围如图中黑色区域所示:如果在地图中的灰色所标识的平原上部署一支炮兵部队,则图中的黑色的网格表示它能够攻击到的区域:沿横向...原创 2022-03-02 19:43:41 · 175 阅读 · 0 评论 -
国王 状压dp
在N \times NN×N的棋盘里面放KK个国王,使他们互不攻击,共有多少种摆放方案。国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共88个格子。输入格式只有一行,包含两个数N, KN,K。输出格式所得的方案数。样例Inputcopy Outputcopy 3 2 16 数据范围与提示1 \le N \le 9, 0 \le K \le N \times N1≤N≤9,0≤K≤N×N...原创 2022-03-02 19:35:59 · 420 阅读 · 0 评论 -
选课 洛谷P2014 树形dp
题目描述在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程来学习,在课程里有些课程必须在某些课程之前学习,如高等数学总是在其它课程之前学习。现在有NN门功课,每门课有个学分,每门课有一门或没有直接先修课(若课程 a 是课程 b 的先修课即只有学完了课程 a,才能学习课程 b)。一个学生要从这些课程里选择MM门课程学习,问他能获得的最大学分是多少?输入格式第一行有两个整数NN,MM用空格隔开。(1 \leq N \leq 3001≤N≤300,1 \leq M...原创 2022-02-27 18:24:13 · 212 阅读 · 0 评论 -
宠物小精灵之收服 01背包 POJ4102
宠物小精灵是一部讲述小智和他的搭档皮卡丘一起冒险的故事。一天,小智和皮卡丘来到了小精灵狩猎场,里面有很多珍贵的野生宠物小精灵。小智也想收服其中的一些小精灵。然而,野生的小精灵并不那么容易被收服。对于每一个野生小精灵而言,小智可能需要使用很多个精灵球才能收服它,而在收服过程中,野生小精灵也会对皮卡丘造成一定的伤害(从而减少皮卡丘的体力)。当皮卡丘的体力小于等于0时,小智就必须结束狩猎(因为他需要给皮卡丘疗伤),而使得皮卡丘体力小于等于0的野生小精灵也不会被小智收服。当小智的精灵球用完时,狩猎也宣告结束原创 2021-12-24 13:21:33 · 221 阅读 · 0 评论 -
股票买卖 POJ 4121 动态规划
描述最近越来越多的人都投身股市,阿福也有点心动了。谨记着“股市有风险,入市需谨慎”,阿福决定先来研究一下简化版的股票买卖问题。假设阿福已经准确预测出了某只股票在未来 N 天的价格,他希望买卖两次,使得获得的利润最高。为了计算简单起见,利润的计算方式为卖出的价格减去买入的价格。同一天可以进行多次买卖。但是在第一次买入之后,必须要先卖出,然后才可以第二次买入。现在,阿福想知道他最多可以获得多少利润。输入输入的第一行是一个整数 T (T <= 50) ,表示一共有 T 组数据。接下原创 2021-12-23 20:51:27 · 302 阅读 · 0 评论 -
切割回文 POJ 4122 动态规划
描述阿福最近对回文串产生了非常浓厚的兴趣。如果一个字符串从左往右看和从右往左看完全相同的话,那么就认为这个串是一个回文串。例如,“abcaacba”是一个回文串,“abcaaba”则不是一个回文串。阿福现在强迫症发作,看到什么字符串都想要把它变成回文的。阿福可以通过切割字符串,使得切割完之后得到的子串都是回文的。现在阿福想知道他最少切割多少次就可以达到目的。例如,对于字符串“abaacca”,最少切割一次,就可以得到“aba”和“acca”这两个回文子串。输入输入的第一行是一个整数原创 2021-12-22 22:05:44 · 562 阅读 · 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一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡原创 2021-12-15 20:08:39 · 213 阅读 · 0 评论 -
石子归并 II
N堆石子摆成一个环。现要将石子有次序地合并成一堆。规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的代价。计算将N堆石子合并成一堆的最小代价。例如: 1 2 3 4,有不少合并方法1 2 3 4 => 3 3 4(3) => 6 4(9) => 10(19)1 2 3 4 => 1 5 4(5) => 1 9(14) => 10(24)1 2 3 4 => 1 2 7(7) => 3 7(10) => 10(原创 2021-12-11 16:56:36 · 328 阅读 · 0 评论 -
The Fewest Coins 找零钱
Description农夫John想到镇上买些补给。为了高效地完成任务,他想使硬币的转手次数最少。即使他交付的硬币数与找零得到的的硬币数最少。 John想要买T(1<=T<=10000)样东西。有N(1<=n<=100)种货币参与流通,面值分别为V1,V2..Vn (1<=Vi<=120)。John有Ci个面值为Vi的硬币(0<=Ci<=10000)。我们假设店主有无限多的硬币,并总按最优方案找零。Input* Line 1: 两个整数 N 与 T原创 2021-12-03 20:46:38 · 309 阅读 · 0 评论 -
Add One
You are given an integernn. You have to applymmoperations to it.In a single operation, youmustreplace every digitddof the number with the decimal representation of integerd + 1d+1. For example,19121912becomes2102321023after applying the opera...原创 2021-12-03 15:44:50 · 394 阅读 · 0 评论 -
Multiplication Puzzle 区间dp
The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points equal to the product of the number on the card taken and the numbers on原创 2021-12-03 11:49:36 · 314 阅读 · 0 评论 -
石子归并 I 区间dp
N堆石子摆成一条线。现要将石子有次序地合并成一堆。规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的代价。计算将N堆石子合并成一堆的最小代价。例如: 1 2 3 4,有不少合并方法1 2 3 4 => 3 3 4(3) => 6 4(9) => 10(19)1 2 3 4 => 1 5 4(5) => 1 9(14) => 10(24)1 2 3 4 => 1 2 7(7) => 3 7(10) => 10(20原创 2021-12-03 09:41:16 · 225 阅读 · 0 评论 -
Advanced Fruits 最长公共子序列+打印
The company "21st Century Fruits" has specialized in creating new sorts of fruits by transferring genes from one fruit into the genome of another one. Most times this method doesn't work, but sometimes, in very rare cases, a new fruit emerges that tastes l原创 2021-12-01 20:32:48 · 291 阅读 · 0 评论 -
Coins 多重背包转化为01背包和完全背包
Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known th原创 2021-11-30 19:34:50 · 188 阅读 · 0 评论 -
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原创 2021-11-30 16:16:41 · 258 阅读 · 0 评论 -
Buying Hay 购买干草 完全背包
Description约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草,他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号。第i个公司卖的干草包重量为Pi(1≤Pi≤5000)磅,需要的开销为Ci(l≤Ci≤5000)美元.每个干草公司的货源都十分充足,可以卖出无限多的干草包. 帮助约翰找到最小的开销来满足需要,即采购到至少H磅干草.Input第1行输入N和H,之后N行每行输入一个Pi和Ci.Output最小的开销.Sample I..原创 2021-11-29 16:40:20 · 239 阅读 · 0 评论 -
开心的金明 01背包
金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间。更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NN元钱就行”。今天一早金明就开始做预算,但是他想买的东西太多了,肯定会超过妈妈限定的NN元。于是,他把每件物品规定了一个重要度,分为55等:用整数1 \sim 51∼5表示,第55等最重要。他还从因特网上查到了每件物品的价格(都是整数元)。他希望在不超过NN元(可以等于NN元)的前提下,使每件物品的价格与重要...原创 2021-11-28 22:39:57 · 96 阅读 · 0 评论 -
Nun Heh Heh Aaaaaaaaaaa 动态规划
Vasily Tadokorov is a stringologist. He thinks a string is fragrant if it can be divided into two parts ―\texttt{nunhehheh}nunhehhehas the prefix and a number of (excluding00)\texttt{a}aas the suffix. For example,\texttt{nunhehhehaaaaaa}nunhehhehaaaa...原创 2021-11-25 23:37:35 · 451 阅读 · 0 评论 -
Super Jumping Jumping Jumping 动规
Nowadays, 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.The game can be played by two or more than two players. It consist原创 2021-11-22 11:21:23 · 237 阅读 · 0 评论
分享