动态规划
文章平均质量分 78
云淡风轻jzl
一路脚踏实地,不忘仰望星空。
展开
-
Codeforces-The Sports Festival-贪心+dp
题目描述:The student council is preparing for the relay race at the sports festival.The council consists of n members. They will run one after the other in the race, the speed of member i is si. The discrepancy di of the i-th stage is the difference between原创 2021-04-19 11:29:59 · 307 阅读 · 0 评论 -
牛客3006F-碎碎念-dp+前缀和
链接:https://ac.nowcoder.com/acm/contest/3006/F来源:牛客网题目描述:在ACM比赛里,除了CE以外都是有效的提交。每一个提交都会有其评测的结果,或是AC,或是RJ(Rejected,包含各种不通过的情况)。往往一个人上去提交的时候,总有一个队友会坐在边上等着结果。那个人,往往都是只读题不写题的云选手~牛牛战队里也有这样的云选手——牛能。当牛能看到有...原创 2020-02-13 20:02:59 · 324 阅读 · 0 评论 -
牛客3005F-树上博弈-树形dp
链接:https://ac.nowcoder.com/acm/contest/3005/F来源:牛客网题目描述:现有一个 n 个点,n-1条边组成的树,其中 1 号点为根节点。牛牛和牛妹在树上玩游戏,他们在游戏开始时分别在树上两个不同的节点上。在游戏的每一轮,牛牛先走一步,而后牛妹走一步。他们只能走到没有人的空节点上。如果谁移动不了,就输掉了游戏。现在牛牛和牛妹决定随机选择他们分别的起点...原创 2020-02-11 19:22:56 · 582 阅读 · 0 评论 -
CF1288C-Two Arrays-思维+dp
DescriptionYou are given two integers n and m. Calculate the number of pairs of arrays (a,b) such that:the length of both arrays is equal to m;each element of each array is an integer between 1 an...原创 2020-01-15 09:57:39 · 1164 阅读 · 0 评论 -
牛客-3566B-小琛和他的学校-树形dp
题目描述:链接:https://ac.nowcoder.com/acm/contest/3566/B来源:牛客网小琛是一所学校的校长。他的学校有n个校区(编号1~n),被n-1条双向道路连接,呈树形结构。第i个校区共有Ai个学生。第i天早上,所有的学生会沿最短路走到第i个校区参加活动,晚上再原路返回。一个人通过第j条通道一次(即一人次),需要小琛支付wj的维护费用。小琛想知道第n天...原创 2019-12-27 22:57:28 · 288 阅读 · 0 评论 -
动态规划中三种背包遍历容量的顺序
01背包逆序遍历容量,避免未使用就更新。多重背包用二进制优化后转成01背包再逆序遍历容量。完全背包顺序遍历容量,每种物品使用次数不限,能更新就更新。...原创 2019-08-15 18:57:37 · 318 阅读 · 0 评论 -
SPOJ-BALNUM-Balanced Numbers-状压dp+数位dp
DescriptionBalanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if:Every even digit appears an odd number of times in its decimal rep...原创 2019-08-15 19:56:18 · 173 阅读 · 0 评论 -
HDU 2809-God of War-状压dp-入门
DescriptionAt 184~280 A.D ,there were many kingdoms in China. Three strongest among them are “Wei”, “Shu”, “Wu”. People call this period as “Three Kingdoms”.HH is a super “Three Kingdoms” fan, becau...原创 2019-08-16 09:58:52 · 254 阅读 · 0 评论 -
HDU 3652-B-number-数位dp-模板
DescriptionA 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...原创 2019-08-16 10:20:04 · 157 阅读 · 0 评论 -
HDU 4734-F(x)-数位dp-好题
DescriptionFor a decimal number x with n digits (AnAn-1An-2 … A2A1), we define its weight as F(x) = An * 2n-1 + An-1 * 2n-2 + … + A2 * 2 + A1 * 1. Now you are given two numbers A and B, please calcul...原创 2019-08-16 10:40:27 · 159 阅读 · 0 评论 -
HDU 5009-Paint Pearls-dp+双向链表
DescriptionLee has a string of n pearls. In the beginning, all the pearls have no color. He plans to color the pearls to make it more fascinating. He drew his ideal pattern of the string on a paper a...原创 2019-08-27 15:59:48 · 185 阅读 · 0 评论 -
QDU 80-树结构重逢-树形dp-模板
题目描述:给定一颗包含n个节点的无根树,并且把节点从1-n编号。现在让你求对于每个点,求出所有点到这个点的距离的和(距离当然是最短距离了…)。输入描述:第一行包含一个正整数n ( n <= 100000 ),表示节点的个数。 后面(n - 1)行,每行两个整数(u, v)表示树的边u-v。输出描述:每行一个整数,第i(i = 1,2,…n)行表示所有节点到第i个点的距离之和。(i...原创 2019-10-05 16:38:56 · 281 阅读 · 0 评论 -
HDU 2196-Computer-树形dp-模板
DescriptionA school bought the first computer some time ago(so this computer’s id is 1). During the recent years the school bought N-1 new computers. Each new computer was connected to one of settled...原创 2019-08-15 18:46:14 · 128 阅读 · 0 评论 -
CF 1114D-Flood Fill-n2复杂度的区间dp
DescriptionYou are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color ci.Let’s say, that two squares i and j belong to the s...原创 2019-08-15 17:52:45 · 289 阅读 · 0 评论 -
有序的动态规划-Proud Merchants
题目描述:Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if t...原创 2019-06-30 19:43:44 · 230 阅读 · 0 评论 -
POJ 3260-The Fewest Coins-混合背包+二进制优化
Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he always pays for his goods in such a way that the smallest number of coins changes hands, i.e., the number of coin...原创 2019-07-24 13:59:40 · 162 阅读 · 0 评论 -
HDU1024-Max Sum Plus Plus-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 ...原创 2019-07-24 14:46:13 · 166 阅读 · 0 评论 -
CF 245H-Queries for Number of Palindromes-两次区间dp
You’ve got a string s = s1s2… s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 ≤ li ≤ ri ≤ |s|). The answer to t...原创 2019-07-25 10:06:36 · 130 阅读 · 0 评论 -
HDU 5707-Combine String-动态规划
Given three strings a, b and c, your mission is to check whether c is the combine string of a and b.A string c is said to be the combine string of a and b if and only if c can be broken into two subs...原创 2019-07-26 09:35:43 · 257 阅读 · 2 评论 -
UVA10003-Cutting Sticks-区间dp
You have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery,Inc. (ACM), charges money according to the length of the stick being cut. Their procedure of work re...原创 2019-07-22 15:31:02 · 298 阅读 · 0 评论 -
POJ1014-HDU1059-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 v...原创 2019-07-22 16:12:43 · 167 阅读 · 0 评论 -
POJ2955-Bracket-区间dp
We give the following inductive definition of a “regular brackets” sequence:1)the empty sequence is a regular brackets sequence.2)if s is a regular brackets sequence, then (s) and [s] are regular br...原创 2019-07-22 16:48:38 · 133 阅读 · 0 评论 -
ZOJ 3211-Dream City-排序+动态规划
JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are n trees in the yard. Let’s call them tree 1, tree 2 …and tree n. At the first day, each tree i has ai coins on it (i=1, ...原创 2019-07-26 20:25:09 · 177 阅读 · 0 评论 -
ZOJ 2955-Interesting Dart Game-完全背包+贪心处理
Recently, Dearboy buys a dart for his dormitory, but neither Dearboy nor his roommate knows how to play it. So they decide to make a new rule in the dormitory, which goes as follows:Given a number N,...原创 2019-07-26 21:06:02 · 155 阅读 · 0 评论 -
HDU 6630-permutation 2-思维+dp
DescriptionYou are given three positive integers N,x,y.Please calculate how many permutations of 1∼N satisfies the following conditions (We denote the i-th number of a permutation by pi):p1=xp...原创 2019-08-07 09:49:06 · 302 阅读 · 0 评论 -
蓝桥杯2017年第八届-对局匹配
题目描述:小明喜欢在一个围棋网站上找别人在线对弈。这个网站上所有注册用户都有一个积分,代表他的围棋水平。小明发现网站的自动对局系统在匹配对手时,只会将积分差恰好是K的两名用户匹配在一起。如果两人分差小于或大于K,系统都不会将他们匹配。现在小明知道这个网站总共有N名用户,以及他们的积分分别是A1, A2, … AN。小明想了解最多可能有多少名用户同时在线寻找对手,但是系统却一场对局都匹配不起...原创 2019-05-10 10:22:27 · 196 阅读 · 0 评论