原题链接 大意 n*n正方形 有黑有白 每次可以选择一个 矩形把它全变成白色,代价是max(长,宽) 求吧 整个正方形 全变白 的最小代价 数据范围 n <= 50 题解 首先如果 我们刷了两个有相邻边或重叠的 白色矩形 那么 假设他们的代价分别为 x和y 那么 一定有 一个 边长为x+y的正方形 完全覆盖了这两个白色矩形 dis|row| <= rowX+roxY <= costX+costY = x+y dis|col| <= colX+roxY <= costX+cos…
https://codeforces.com/contest/1198/problem/D 原来是dp的思路,而且是每次切成两半向下递归.好像在哪里见过类似的,貌似是紫书的样子. 再想想好像就很显然的样子,并不会出现奇奇怪怪的合并的样子. #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int dp[51][51][51][51]; char g[51][51]; int main() { #if…
题意:有一个n * n的棋盘,每个棋盘有某些矩形区域被染成了黑色(这些矩形区域有可能相交),问把所有黑色区域染成白色的最小花费是多少?你每次可以选择把一个矩形区域染成白色,花费是染色的矩形区域长和宽的最小值. 思路:容易发现,假设一个矩形的坐标是(l1, r1, l2, r2),假设(l2 - l1 < r2 - r1), 那么我们把r1和r2变成1和n对答案不会有影响.那么,我们发现问题转化为了选最少的行和列使得所有的黑色区域被覆盖,换句话说,就是所有的点至少被一个行货列所覆盖.我们把行看成左…
题目传送门 题意: 有一个$n∗n$的网格,网格中有一些矩形是黑的,其他点都是白的. 你每次可以花费$ min (h,w)$的代价把一个$h*w$的矩形区域变白.求把所有黑格变白的最小代价. 思路: 对于一列来说,如果我们要把这一列涂白,那必定会一涂到底,这样对结果只会有好处.行也是这样. 明白了这个之后,这道题就变成了一道需要离散化的最小点覆盖问题,离散化时注意这个是网格,所以$x2,y2$都需要加1处理,然后跑一边网络流即可. #pragma GCC optimize (2) #pragma…
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include…
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Memory limit 262144 kB Source Codeforces Round #605 (Div. 3) Tags brute force   dp   *1500 Site https://codeforces.com/problemset/problem/1272/D 题面 Exam…
B. Painting The Wall time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are p…
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his…
                                                                               D. Painting The Wall   User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are n…
Time limit 1000 ms Memory limit 262144 kB 解题思路 一堆循环嵌套的那种dp,不好想.但是可以搜啊,很暴力的.记忆化一下就好. 我们定义搜索函数\(\text{search}(x1,y1,x2,y2)\),代表将矩形区域\([x1,x2]\).\([y1,y2]\)内部全部染白的最小代价. 我们可以知道,如果这个区域内全白,那么代价显然就是0. 如果全黑,那么不妨一次性全部染白,拆开成几个小的矩形并分别染色不会使结果更优.证明(其他大小的矩形可以类比):\…