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…
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));…
递归方法解决数塔问题 状态转移方程:d[i][j]=a[i][j]+max{d[i+1][j],d[i+1][j+1]} 注意:1\d[i][j]表示从i,j出发的最大总和;2\变界值设为0;3\递归变界为n;4\结果为d[1][1] #include<iostream> #include<algorithm> using namespace std; #define maxn 1000+5 int n; int a[maxn][maxn]; int d[maxn][maxn];…
Description There are two rows of positive integer numbers. We can draw one line segment between any two equal numbers, with values r, if one of them is located in the first row and the other one is located in the second row. We call this line segmen…