随笔分类 -  状态压缩

摘要:题目大意 考虑一个 $4$ 行 $n$ ($4\le n\le 1000$)列的矩阵 $f$,$f$ 中的元素为 或 。 对 $f$ 进行若干次如下变换: 将一个 $k\times k$($1\le k \le 4$)的子矩阵中的元素全部替换为 ,代价为 $a_k$( $1 \le a_k \le 阅读全文
posted @ 2017-12-20 17:06 Pat 阅读(515) 评论(0) 推荐(0)
摘要:问题1 给出一个$1 \sim n$的全排列$P$, 求它是所有全排列的第几个 (0 based)? 做法 从左到右看$P$的每一位, 考虑当前可以确认有多少全排列在$P$之前. $ $: 所有第一位是$1 \sim P_1 1$的排列都在$P$之前, 共有 $(P_1 1)(n 1)!$个. $P 阅读全文
posted @ 2016-11-07 15:58 Pat 阅读(147) 评论(0) 推荐(0)
摘要:Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description Hearthstone is an online collectible card game fr 阅读全文
posted @ 2016-08-09 18:30 Pat 阅读(541) 评论(0) 推荐(0)
摘要:传送门DescriptionA kingdom has n cities numbered 1 to n, and some bidirectional roads connecting cities. The capital is always city 1.After a war, all th... 阅读全文
posted @ 2015-08-14 19:01 Pat 阅读(205) 评论(0) 推荐(0)
摘要:位运算是状态压缩DP的基础。 算符 C/C++中的位运算算符(按优先级排序): 红色算符与位运算算符的优先级高低顺序容易弄混,这里强调一下。 ! ~ (bitwise NOT) 按位非 ~x * / % + - > >= < <= << >> (bitwise left shift and righ 阅读全文
posted @ 2015-05-03 16:24 Pat 阅读(237) 评论(0) 推荐(0)