摘要: 区间dp。 用f[l][r]表示从l到r最少需要染几次色。 状态转移方程: 1.f[l][r]=min(f[l][i],f[i+1][r]) (l #include #include using namespace std; const int maxn = 200 + 10; int n; int f[maxn][maxn]; char s[maxn]; int dp(int l,in... 阅读全文
posted @ 2016-07-12 23:04 invoid 阅读(460) 评论(0) 推荐(0) 编辑
摘要: 主席树。 我分不清主席树和可持久化线段树。。 用主席树记录历史版本。 然后每个节点保存一个深度,代表以自己为根的树的深度。 合并时将深度小的树合进深度大的树。 3673也是一样的,不过那道题不强制在线。 #include #include #include using namespace std; const int maxn = 200000 + 10; const int m... 阅读全文
posted @ 2016-07-12 16:10 invoid 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 区间dp。 用f[l][r]表示区间[l,r]最短能缩到多短。 然后状态转移方程有俩种 1.不折叠 f[l][r]=f[l][i]+f[i+1][r]. (l= #include #include using namespace std; const int maxn = 200 + 10; char s[maxn]; int f[maxn][maxn]; int h(int i,i... 阅读全文
posted @ 2016-07-12 09:53 invoid 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 区间dp。 bool t代表区间内是否能含M。 如果不能含M的话有 res=min{f[l][i][0]+r-i}。(i>1][t]+1) (后半串用1个R替代)。 如果t=1时,除上面俩个还有res=min{f[l][i][1]+1+f[i+1][r][1]}。 状态和3种状态转移方程比较难想。很大程度是因为对区间dp不熟悉。 #include #include #include... 阅读全文
posted @ 2016-07-12 00:29 invoid 阅读(389) 评论(0) 推荐(1) 编辑