题目链接: http://codeforces.com/problemset/problem/149/D D. Coloring Brackets time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Toda…
题目链接:https://vjudge.net/problem/CodeForces-149D D. 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 tho…
Coloring Trees Problem 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 with integers from 1 to n fr…
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 walked in the park where n trees grow. They decided to be…
题目:https://codeforces.com/problemset/problem/711/C 题意:给你n,m,k,代表n个数的序列,有m种颜色可以涂,0代表未涂颜色,其他代表已经涂好了,连着一段是相同颜色的是一个连通块,求正好有k个连通块的最小花费 思路:首先每个位置有可能有m中颜色,而且要满足k个,我们我们可以推出所有情况 dp[n][m][k] n代表前n个数 m代表当前涂m色 k代表满足k个了 #include<cstdio> #include<cmath> #in…
题目链接:https://codeforces.com/contest/608/problem/D 题意:给出n个宝石的颜色ci,现在有一个操作,就是子串的颜色是回文串的区间可以通过一次操作消去,问最少需要多少次操作可以消除所有的宝石.(每次操作消除一个回文串,最少操作次数清楚字符串) 题解:dp[l][r]表示区间(l,r)的最少操作次数,对于一个区间(l,r),有两种转移:①若存在c_l = c_i(l <= i <= r),可以由dp[l][i] + dp[i + 1][r]转移:②若c…
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase Engl…
题目链接: codeforces 149D Coloring Brackets 题目描述: 给一个合法的括号串,然后问这串括号有多少种涂色方案,当然啦!涂色是有限制的. 1,每个括号只有三种选择:涂红色,涂蓝色,不涂色. 2,每对括号有且仅有其中一个被涂色. 3,相邻的括号不能涂相同的颜色,但是相邻的括号可以同时不涂色. 解题思路: 这个题目的确是一个好题,无奈我太蠢,读错题意.以为(())这样的括号序列在涂色的时候,第一个括号与第三个括号也可以看做是一对.这样的话还要统计合法的括号匹配数目,还…
题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间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…
题目链接:http://codeforces.com/problemset/problem/149/D 继续区间DP啊.... 思路: 定义dp[l][r][c1][c2]表示对于区间(l,r)来说,l用c1染色,r用c2染色的方案数. 那么: 1,如果括号l和括号r匹配(即括号l和r为一对括号)那么dp[l][r][c1][c2]+=dp[l+1][r-1][i][j](i与c1为不同的颜色,j与c2是不同的颜色,或i=0或j=0) 2,如果括号l和括号r不匹配,那么dp[l][r][c1][…