DP训练
……
逃夭丶
你是我荒唐青春里唯一的认真
展开
-
Dima and a Bad XOR(贪心)
Student Dima from Kremland has a matrix a of size n×m filled with non-negative integers.He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selec...原创 2019-05-19 16:25:37 · 239 阅读 · 0 评论 -
Combine String(动态规划)
http://acm.hdu.edu.cn/showproblem.php?pid=5707Problem Description 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...原创 2019-07-26 18:48:25 · 195 阅读 · 0 评论 -
Play Game(记忆化搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=4597Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a s...原创 2019-07-26 19:11:38 · 138 阅读 · 0 评论 -
FatMouse's Speed(DP-记录路径)
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<map>#include<queue>#include<utility>#include<se...原创 2019-07-27 14:42:26 · 175 阅读 · 0 评论 -
Jesus Is Here(递推规律)
Problem Description I’ve sent Fang Fang around 201314 text messages in almost 5 years. Why can’t she make sense of what I mean? “But Jesus is here!" the priest intoned.”Show me your messages." F...原创 2019-07-27 18:28:04 · 157 阅读 · 0 评论 -
最长回文问题
一、最长回文子串 最长回文子串的问题描述: 给出一个字符串 S ,求 S 的最长回文子串的长度。 样例: 字符串"PATZJUJZTACCBCC"的最长回文子串为"ATZJUJZTA",长度是9方法一: 暴力出奇迹,O(n3),枚举子串的两个端点 i 和 j,判断在[i,j]区间内的子串是否为回文。方法二: 转化为LCS问题:把字符串 S 倒过来变成字符串 T ,然后对...原创 2019-07-28 16:18:28 · 408 阅读 · 0 评论 -
Classy Numbers (数位dp)
题目链接:https://cn.vjudge.net/problem/CodeForces-1036C题意:求有多少数1-9的数字不超过3个题解:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#incl...原创 2019-08-13 12:59:41 · 88 阅读 · 0 评论 -
树形DP—最小点覆盖
对于最小覆盖点,每个点只有两种状态,即属于点覆盖或者不属于点覆盖: 1. dp[i][1] 表示点 i 属于点覆盖,并且以点 i 为根的子树中所连接的边都被覆盖的情况下点覆盖级中所包含最少点的个数。 对于此状态,dp[i][1],等于每个儿子节点的两种状态的最小值之和 + 1,dp转移方程: dp[i][1] = 1 + ∑ (u取ii的子节点) min(dp[u][0],dp[u...原创 2019-08-11 20:47:15 · 887 阅读 · 0 评论 -
树形DP—最小支配集
考虑到最小支配集,每个点都有两种状态,即属于支配集合或者是不属于支配集合,其中不属于支配集合时此点还需要被覆盖,被覆盖也有两种状态,即被子节点覆盖或者被父节点覆盖。总结起来就是三种状态,即:dp[i][1],表示点 i 属于支配集合,并且以点 i 为根的子树都覆盖了的情况下支配集中所包含最少点的个数对于第一种状态,dp[i][1]含义为点 i 属于支配集合,那么依次取每个儿子节点三种状态中的...原创 2019-08-12 14:09:36 · 234 阅读 · 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...原创 2019-07-22 19:57:13 · 84 阅读 · 0 评论 -
Free Candies(记忆化搜索)
Little Bob is playing a game. He wants to win some candies in it - as many as possible. There are 4 piles, each pile contains N candies. Bob is given a basket which can hold at most 5 candies. Eac...原创 2019-07-22 17:05:55 · 179 阅读 · 0 评论 -
命运(dp基础题)
穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个机关。要知道,不论何人,若在迷宫中被困1小时以上,则必死无疑!可怜的yifenfei为了去救MM,义无返顾地跳进了迷宫。让我们一起帮帮执着的他吧!命运大迷宫可以看成是一个两维的方格阵列,如下图所示: yifenfei一开始在左上角...原创 2019-05-19 19:59:19 · 136 阅读 · 0 评论 -
九连环问题
九连环是我国传统的民间智力玩具,玩具上面有九个连环套在杆上,目标就是通过一定的方式将九个连环从杆上全部取下来。 玩法是这样的:1、对每个环,有2种操作:把这个环放到杆上或把这个环从杆上取下2、你可以随意的对第1个环进行操作3、如果你想对第i个环(i>1)进行操作,你必须将第i-1个环放在杆上,且必须把前i-2个环从杆上取下九连环问题: 有两种题型,题型一:就是简单的让你输...原创 2019-05-30 00:26:48 · 1086 阅读 · 0 评论 -
浅谈矩阵快速幂
矩阵快速幂,从字面上来说就是矩阵之间的乘法运算关系,它分为四部分: 一、矩阵乘法函数 二、矩阵快速幂函数 三、最初矩阵的求解 四、结果的求解第一和第二步又不变一些板子:struct In{ ll m[maxn][maxn]; //定义结构体矩阵};In _mul(In x,In y,int n) //n × n的矩阵{ In p; //存放 x矩阵 X ...原创 2019-07-02 21:26:24 · 143 阅读 · 0 评论 -
Diophantus of Alexandria(数论)
Problem Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first mathematicians to study equations where variables were restricted to integral va...原创 2019-07-23 21:50:46 · 114 阅读 · 0 评论 -
子序列之和系列
一、一段最长连续子序列之和问题: 给定一个数字序列:A1,A2 …… An,求i,j(i<=j<=n),使得Ai + Ai+1 + …… + Aj最大,输出最大和。 样例:-2 11 -4 13 -5 -2 输出:20子问题:取一段连续子序列,要求是该序列和最大思路:用dp[i]表示 1到 i 的序列和,而dp[i]的值与dp[i-1]和A[i]有关,dp[i] = m...原创 2019-07-24 16:41:49 · 766 阅读 · 0 评论 -
Leading and Trailing(数论/n^k前三位)
You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.Input Input starts with an integer T (≤ 1000), denoting the n...原创 2019-07-22 11:29:13 · 123 阅读 · 0 评论 -
Monkey and Banana(贪心+DP)
A 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 mo...原创 2019-07-22 13:38:49 · 190 阅读 · 0 评论 -
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 workr...原创 2019-07-22 14:12:14 · 65 阅读 · 0 评论 -
树形DP—最大独立集
最大独立集:对于图G=<V,E>,从V中取尽量多的点组成一个集合,使得这些点之间没有边相连对于最大独立集,每个点也只有两种状态,即属于点 i 属于独立集或者不属于独立集两种情况:dp[i][1]表示点 i 属于独立集的情况下,最大独立集中点的个数.dp[i][0]表示点 i 不属于独立集的情况下,最大独立集中点的个数.对于第一种状态dp[i][1],由于 i 点属于独立集,所...原创 2019-08-12 14:19:41 · 228 阅读 · 0 评论