摘要:
用二进制来表示一个问题的子问题是否使用过,例如,101表示1、3已经使用,2没有使用过。由于使用指数级别的数据所以一般使用状压DP的数据范围不会很大,不超过30,一般使用在解决NP问题的小规模求解中。 一些操作: x>>n x<<n x&y x|y x^y(异或) 1<<i 左移i位 x|(1<<i 阅读全文
摘要:
1、滑雪:从每个点开始枚举,记忆化搜索,记录dp[x][y] #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<stack> #include<cstdio> #include<queu 阅读全文
摘要:
一般是由长度小的子问题推到长度大的子问题,解法一般比较固定,先枚举长度再枚举左端点 最后枚举中间的分割点 通过小区间的情况扩展到大区间 1、合并石子1 线性的,合并相邻的,通过计算前缀和减少了计算量,但也是O(N^3) cin>>n; for(int i=1;i<=n;i++) { cin>>a[i 阅读全文
摘要:
1、背包问题--竞赛真理 每个物品有多种采用方式 http://www.rqnoj.cn/problem/160 #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<stack> #inc 阅读全文