luogu P3936 Coloring】的更多相关文章

[返回模拟退火略解] 题目描述 在一个 n×mn\times mn×m 的矩阵中,每个点都染了一种颜色(只能是 [1,c][1,c][1,c] 中的一种),求一种方案,使得相邻异色点对数最小. Solution 3936\text{Solution 3936}Solution 3936 这是一道好题.正所谓代码五分钟,调参两百年. 随机一个矩阵作为初始矩阵.每次降温时尝试交换两个随机元素,判断交换后是否更优.详见代码. 对于每次交换,更新 calccalccalc 函数可以在 O(1)O(1)O…
考虑搜索,发现复杂度爆炸        贪心,正确性过低(~~实测爆炸~~) 于是,~~发现~~这题是模拟退火 这里不讲解退火的定义了,初学退火可以去平衡点 退火本身维护一个答案图像,答案的q,当前图像,当前的q 暴力根据计算图像计算q即可 关于这题我们发现如果任由其随机,可能会导致偏差太大 但如果过多修正偏差,可能导致其跃出局部最优解的能力降低 于是我加了这么一句话 if (curq - ansq >= (temp * 90)){ for (ri i = 1; i <= n; ++i) fo…
虽然有点久远  还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题  沉迷游戏,伤感情 #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; ],last,now,sum[],s; deque<lon…
题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题目,没有打答案之间的换行,wa了好几次 解决所有"构造"问题都要按照如下的步骤: 寻找特例.特征 建立模型 一般化模型 寻找特例 (1) 我们假设结点数为1,显然答案为0,因为这棵树的边集为空. (2) 当结点数为2时,答案就是d[1][2],即(1,2)的距离. (3) 当结点数为3时呢…
题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered wit…
题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间DP 用栈先处理匹配 f[i][j][0/1/2][0/1/2]表示i到ji涂色和j涂色的方案数 l和r匹配的话,转移到(l+1,r-1) 不匹配,i的匹配p一定在l和r之间,从p分开转移 听说用记忆化搜索比较快,可以像树形DP那样写记忆化搜索,也可以传统的四个参数那样写 用循环+条件判断,简化状态转移的枚举 注意细节 见代码 #include<iostream> #include<cstdio> #include&l…
C. Coloring Trees   ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right…
题目链接:C. Coloring Trees 题意:给出n棵树的颜色,有些树被染了,有些没有.现在让你把没被染色的树染色.使得beauty = k.问,最少使用的颜料是多少.   K:连续的颜色为一组,一共有多少组. 颜料用量:p[i][j]表示第i棵树用颜料j染色 需要p[i][j]颜料. 思路:DP. dp方程:dp[i][j][k] = a 表示前i棵树beauty = j,且第j棵树染色为k时,需要的最少颜料为a. 状态转移:初始化第一棵树dp[1][1][col[1]or(1~m)].…
Coloring Brackets time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will…
传送门:http://codeforces.com/problemset/problem/711/C 题目: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder and Chris the Baboon has arrived at Udayland! They wal…