
动态规划
文章平均质量分 68
小坏蛋_千千
im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......
展开
-
LOJ 6160 二分图染色 (dp,组合数学)
题目描述 给定一个完全二分图,图的左右两边的顶点数目相同。我们要把图中的每条边染成红色、蓝色、或者绿色,并使得任意两条红边不共享端点、同时任意两条蓝边也不共享端点。计算所有满足条件的染色的方案数,并对 109+7109+710^9+7 取模。 输入格式 二分图单边的顶点数目 nnn 。 输出格式 输出一个整数,即所求的答案。...原创 2018-04-06 21:56:38 · 973 阅读 · 0 评论 -
POJ 3254 Corn Fields (状压dp)
Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares.原创 2017-08-31 21:57:50 · 280 阅读 · 0 评论 -
51nod 1405 树的距离之和 (树形dp)
Description 给定一棵无根树,假设它有n个节点,节点编号从1到n ,求任意两点之间的距离(最短路径)之和。 Input 第一行包含一个正整数n (n <= 100000),表示节点个数。 后面(n - 1)行,每行两个整数表示树的边。 Output 每行一个整数,第i(i = 1,2,…n)行表示所有节点到第i个点的距离之和。 Input示例41 23 2原创 2017-09-09 10:39:34 · 543 阅读 · 0 评论 -
51nod 1791 合法括号子段 (dp)
Description 有一个括号序列,现在要计算一下它有多少非空子段是合法括号序列。 合法括号序列的定义是: 空序列是合法括号序列。 如果 S 是合法括号序列,那么 (S) 是合法括号序列。 如果 A 和 B 都是合法括号序列,那么 AB 是合法括号序列。 Input 多组测试数据。 第一行有一个整数 T(1<=T<=1100000) ,原创 2017-09-23 10:33:26 · 564 阅读 · 0 评论 -
HDU 6170 Two strings (dp)
Description Giving two strings and you should judge if they are matched. The first string contains lowercase letters and uppercase letters. The second string contains lowercase letters, upp原创 2017-08-22 19:53:59 · 1661 阅读 · 9 评论 -
HDU 6156 Palindrome Function (数位dp)
Description As we all know,a palindrome number is the number which reads the same backward as forward,such as 666 or 747.Some numbers are not the palindrome numbers in decimal form,but in other base,原创 2017-08-22 21:50:10 · 464 阅读 · 0 评论 -
HDU 6146 Pokémon GO (dp)
Description 众所周知,度度熊最近沉迷于 Pokémon GO。 今天它决定要抓住所有的精灵球! 为了不让度度熊失望,精灵球已经被事先放置在一个2*N的格子上,每一个格子上都有一个精灵球。度度熊可以选择任意一个格子开始游戏,抓捕格子上的精灵球,然后移动到一个相邻的至少有一个公共点的格子上继续抓捕。例如,(2, 2) 的相邻格子有(1, 1), (2, 1原创 2017-08-18 21:22:33 · 941 阅读 · 0 评论 -
HDU 6035 Colorful Tree (树形dp)
Description There is a tree with n nodes, each of which has a type of color represented by an integer, where the color of node i is ci. The path between each two different nodes is unique, of wh原创 2017-07-26 20:35:55 · 584 阅读 · 0 评论 -
HDU 6078 Wavel Sequence (dp)
Description Have you ever seen the wave? It’s a wonderful view of nature. Little Q is attracted to such wonderful thing, he even likes everything that looks like wave. Formally, he defines a sequence原创 2017-08-09 20:29:49 · 577 阅读 · 0 评论 -
hihocoder 1532 最美和弦 (dp)
描述 某个夜晚,Bob将他弹奏的钢琴曲录下来发给Jack,Jack感动之余决定用吉他为他伴奏。 我们可以用一个整数表示一个音符的音高,并可认为Bob弹奏的曲子是由3N个整数构成的一个序列。其中每个整数的取值范围是[-200, 200]。 Jack共弹奏 N 个和弦,每个和弦由三个音符组成。Jack可以自行决定和弦的第一个音符,其后的两个音符由第一个音符与和弦种类所决定。Jac原创 2017-07-24 10:32:50 · 606 阅读 · 0 评论 -
hiho一下 第158周 非法二进制数 (dp)
描述 如果一个二进制数包含连续的两个1,我们就称这个二进制数是非法的。 小Hi想知道在所有 n 位二进制数(一共有2n个)中,非法二进制数有多少个。 例如对于 n = 3,有 011, 110, 111 三个非法二进制数。 由于结果可能很大,你只需要输出模109+7的余数。 输入 一个整数 n (1 ≤ n ≤ 100)。 输出 n 位非法二进制数的数目原创 2017-07-13 17:29:04 · 543 阅读 · 0 评论 -
POJ 3264 Balanced Lineup (RMQ)
Description For 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原创 2017-07-13 15:03:36 · 253 阅读 · 0 评论 -
Codeforces 855 C. Helga Hufflepuff’s Cup (树形dp)
Description Harry, Ron and Hermione have figured out that Helga Hufflepuff’s cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatr原创 2017-09-27 21:29:02 · 685 阅读 · 0 评论 -
HDU 6201 transaction transaction transaction (树形dp)
Description Kelukin is a businessman. Every day, he travels around cities to do some business. On August 17th, in memory of a great man, citizens will read a book named “the Man Who Changed China”. O原创 2017-09-21 09:14:10 · 320 阅读 · 0 评论 -
51nod 1042 数字0-9的数量 (数位dp)
Description 给出一段区间 a-b ,统计这个区间内 0-9 出现的次数。 比如 10-19,1 出现 11 次(10, 11, 12, 13, 14, 15, 16, 17, 18, 19,其中 11 包括 2 个 1 ),其余数字各出现 1 次。 Input 两个数 a,b(1 <= a <= b <= 10^18)...原创 2018-04-10 17:19:36 · 597 阅读 · 0 评论 -
Leetcode 813 Largest Sum of Averages (区间dp)
Description We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the largest score we can achieve? Note ...原创 2018-04-08 15:14:53 · 1411 阅读 · 0 评论 -
Codeforces 933 A. A Twisty Movement (dp)
Description A dragon symbolizes wisdom, power and wealth. On Lunar New Year’s Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to res...原创 2018-02-16 10:32:19 · 853 阅读 · 0 评论 -
Codeforces 834 D. The Bakery (线段树+dp)
Description Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bake...原创 2018-02-15 00:33:17 · 455 阅读 · 0 评论 -
CodeChef STRMRG String Merging (dp)
Description All submissions for this problem are available. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. For a string S, let’s define a function F(S) as原创 2018-01-28 17:43:40 · 275 阅读 · 0 评论 -
Codeforces 814 C. An impassioned circulation of affection (dp)
Description Nadeko’s birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi wil原创 2018-01-28 17:23:17 · 240 阅读 · 0 评论 -
Codeforces 919 D. Substring (记忆化搜索)
Description You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path’s value as the number of the most frequently occurring letter.原创 2018-02-03 09:38:37 · 344 阅读 · 0 评论 -
Codeforces 914 C. Travelling Salesman and Special Numbers (dp)
Description The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive inte原创 2018-01-25 12:23:46 · 500 阅读 · 0 评论 -
Codeforces 560 E. Gerald and Giant Chess (dp,组合数学)
Description Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we’ll just say that the game takes place on an h × w field, and it is painted in two colors, but no原创 2017-12-02 18:52:02 · 381 阅读 · 0 评论 -
51nod 1055 最长等差数列
Description N个不同的正整数,找出由这些数组成的最长的等差数列。 例如:1 3 5 6 8 9 10 12 13 14 等差子数列包括(仅包括两项的不列举) 1 3 5 1 5 9 13 3 6 9 12 3 8 13 5 9 13 6 8 10 12 14 其中6 8 10 12 14最长,长原创 2017-10-04 22:11:42 · 301 阅读 · 0 评论 -
POJ 3368 Frequent values (RMQ)
Description You are given a sequence of n integers a1 , a2 , … , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each原创 2017-10-03 12:46:22 · 960 阅读 · 0 评论 -
HZAU 1199 Little Red Riding Hood (dp)
Description Once upon a time, there was a little girl. Her name was Little Red Riding Hood. One day, her grandma was ill. Little Red Riding Hood went to visit her. On the way, she met a big wolf. “Th原创 2017-04-23 18:02:15 · 760 阅读 · 2 评论 -
POJ 3071 Football (概率dp)
Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order原创 2017-04-20 20:58:43 · 530 阅读 · 0 评论 -
POJ 1080 Human Gene Functions (DP)
Description It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interest原创 2017-02-07 20:47:12 · 544 阅读 · 0 评论 -
POJ 3267 The Cow Lexicon (DP)
Description Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters ‘a’..’z’. Their cowmunication system, based on mooing, is not ver原创 2017-02-07 19:11:13 · 472 阅读 · 2 评论 -
POJ 1836 Alignment (LIS)
Description In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the原创 2017-02-07 18:37:50 · 398 阅读 · 0 评论 -
POJ 1159 Palindrome (LCS)
Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the原创 2017-02-07 17:45:22 · 427 阅读 · 0 评论 -
hihocoder 1453 Rikka with Tree (简单DP)
描述 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的: 勇太有一棵 n 个节点的以1为根的有根树。现在他可以对这棵树进行若干次操作,每一次操作可以选择树上的一个点然后删掉这个点和它的儿子之间的所有边。 现在勇太想要知道对于每一个 k ∈ [1, n],最少需要多少次操作才能让图中恰好存在 k 个联通块。 当然,这个问题对于萌萌哒原创 2016-12-25 21:13:52 · 544 阅读 · 0 评论 -
HDU 3853 LOOPS (概率DP)
Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, she is trappe原创 2016-11-27 14:19:10 · 326 阅读 · 0 评论 -
HDU 3555 Bomb (数位DP)
Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the curren原创 2016-11-19 20:40:52 · 472 阅读 · 0 评论 -
HDU 2476:String painter (区间DP)
String painterProblem Description There are two strings A and B with equal length. Both strings are made up of lower case letters. Now you have a powerful string painter. With the help of the painter原创 2016-11-19 14:44:42 · 492 阅读 · 0 评论 -
HDU 5904:LCIS(LCIS)
LCISTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 440 Accepted Submission(s): 201Problem DescriptionAlex has two sequences原创 2016-09-25 15:45:05 · 641 阅读 · 0 评论 -
SDUT 2623:The number of steps
The number of stepsTime Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^题目描述 Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,th原创 2016-04-19 18:44:08 · 585 阅读 · 0 评论 -
51nod:1002 数塔取数问题
一个高度为N的由正整数组成的三角形,从上走到下,求经过的数字和的最大值。每次只能走到下一层相邻的数上,例如从第3层的6向下走,只能走到第4层的2或9上。 5 8 4 3 6 97 2 9 5例子中的最优方案是:5 + 8 + 6 + 9 = 28Input第1行:N,N为数塔的高度。(2 <= N <= 500)原创 2016-08-05 21:10:01 · 1547 阅读 · 0 评论 -
hihocoder 1469 福字 (dp)
描述 新年到了,你收到了一副画。你想找到里面最大的福字。 一副画是一个n × n的矩阵,其中每个位置都是一个非负整数。 一个福字被定义成是大小为 k 的正方形,满足其中的每个位置上的数都恰好比他的左边的那个和上边的那个大1(如果左边或上边的那个不存在的话就无此要求)。 比如 1 2 3 2 3 4 3 4 5 就是一个福字。(注意左上原创 2017-02-20 14:21:09 · 1109 阅读 · 3 评论 -
POJ 2151 Check the difficulty of problems (概率DP)
Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following two terms:原创 2017-03-03 15:12:54 · 372 阅读 · 0 评论