CodeForces 711C Coloring Trees】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/711/C O(n^4)的复杂度,以为会超时的 思路:dp[i][j][k]表示第i棵数用颜色k涂完后beauty为j #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll inf=1e15; int c[105]; int p[105][105]; ll dp[105][105][105]; int ma…
题目链接: http://codeforces.com/problemset/problem/711/C 题目大意: 给N棵树,M种颜色,已经有颜色的不能涂色,没颜色为0,可以涂色,每棵树I涂成颜色J花费PIJ.求分成K个颜色段(1112221为3个颜色段)的最小花费.无解输出-1. 题目思路: [动态规划] f[i][j][k]表示前i个树分成j段,最后一个颜色是k的花费. 根据当前这棵树是否可以涂色,上一棵树是否可以涂色转移. 直接枚举这个树和上棵树的颜色,N4居然没T. // //by c…
题意:给定n棵树,其中有一些已经涂了颜色,然后让你把没有涂色的树涂色使得所有的树能够恰好分成k组,让你求最少的花费是多少. 析:这是一个DP题,dp[i][j][k]表示第 i 棵树涂第 j 种颜色恰好分成 k 组,然后状态转移方程是什么呢? 如果第 i 棵已经涂了,那么要么和第 i-1 棵一组,要么不和第 i-1 棵一组. 如果第 i 棵没有涂,和上面差不多,就是加上要涂的费用,并且要选择最少的. 代码如下: #pragma comment(linker, "/STACK:1024000000…
简单$dp$. $dp[i][j][k]$表示:前$i$个位置染完色,第$i$个位置染的是$j$这种颜色,前$i$个位置分成了$k$组的最小花费.总复杂度$O({n^4})$. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #incl…
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…
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…
Coloring Trees CodeForces - 711C 题意:有n个点,每个点有一个c值,如果为0表示它没有被染色,否则表示它被染成了c值的颜色.颜色有1到m.把第i棵树染成颜色j所需要的代价是p[i][j].求最小的代价,使得将每棵树都染色,且如果将连续的一串同色的树视为一个集合,共有k个集合.输出代价,如果不可能达到要求输出-1. 方法: $ans[i][j][k]$表示把前i棵树染好,并且最后一种颜色是j,并且总共有k段的最小费用. 首先初始化ans全部值为一个很大的树(方便mi…
题目链接: 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…
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 题目连接: http://www.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…