Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and r…
Palindrome 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 minimal number of characters to be inse…
Palindrome Partitioning II 这个题意思挺好理解,提供一个字符串s,将s分割成多个子串,这些字串都是回文,要求输出分割的最小次数. Example:Input: "aab"Output: 1Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut. 状态:这个题的状态也非常好理解,dp[i]表示将s[0..i]分割成回…
Virus We have a log file, which is a sequence of recorded events. Naturally, the timestamps are strictly increasing. However, it is infected by a virus, so random records are inserted (but the order of original events is preserved). The backup log…
问题描述:有n个矩阵,每个矩阵可以用两个整数a,b来表示 ,表示他的长和宽,矩阵X (a,b) 可以 嵌套 到Y (c,d) 里面当且仅当 a < c && b < d || a < d && b < c . 选出最多这种矩阵.先输出最多的数量,在输出最小字典序路径. 问题分析:本题是DAG(有向无环图)最长路问题,设d[i]为以i结尾的最长链的长度,则状态转移方程为:d[i]=max{0,d[j]|矩形j可以嵌套在矩形i中}+1 ;这里用ma…
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> using namespace std; #define maxn 1000+5 int n; int a[maxn][maxn]; int d[maxn][maxn]; int main(){ for(;cin>>n && n;){ memset(d,,sizeof(d));…