Codeforces Round #369 (Div. 2)-C Coloring Trees
题目大意:有n个点,由m种颜料,有些点没有涂色,有些点已经涂色了,告诉你每个点涂m种颜色的价格分别是多少,
让你求将这n个点分成k段最少需要多少钱。
思路:动态规划,我们另dp[ i ][ j ][ k ] 表示到i个点为止,分成j段,最后一段的颜色为k的最少值,然后就能很容易地
写出状态转移方程。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll dp[N][N][N],c[N],cost[N][N];
int n,m,k;
int main()
{
memset(dp,inf,sizeof(dp));
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++) scanf("%lld",&c[i]);
for(int i=;i<=m;i++) dp[][][i]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++) scanf("%lld",&cost[i][j]);
}
for(int i=;i<=n;i++)
{
for(int j=;j<=k;j++)
{
for(int u=;u<=m;u++)
{
if(c[i] && u!=c[i]) continue;
for(int v=;v<=m;v++)
{
if(u==v) dp[i][j][u]=min(dp[i][j][u],dp[i-][j][v]);
else dp[i][j][u]=min(dp[i][j][u],dp[i-][j-][v]);
}
if(!c[i]) dp[i][j][u]+=cost[i][u];
}
}
}
ll ans=inf;
for(int i=;i<=m;i++) ans=min(ans,dp[n][k][i]);
printf("%lld\n",ans==inf? -:ans);
return ;
}
Codeforces Round #369 (Div. 2)-C Coloring Trees的更多相关文章
- Codeforces Round #369 (Div. 2) C. Coloring Trees(dp)
Coloring Trees Problem Description: ZS the Coder and Chris the Baboon has arrived at Udayland! They ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees 动态规划
C. Coloring Trees 题目连接: http://www.codeforces.com/contest/711/problem/C Description ZS the Coder and ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees DP
C. Coloring Trees ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the pa ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees (DP)
C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)
题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees(简单dp)
题目:https://codeforces.com/problemset/problem/711/C 题意:给你n,m,k,代表n个数的序列,有m种颜色可以涂,0代表未涂颜色,其他代表已经涂好了,连着 ...
- Codeforces Round #369 (Div. 2) C 基本dp+暴力
C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces #369 (Div. 2) C. Coloring Trees (3维dp
http://codeforces.com/group/1EzrFFyOc0/contest/711/problem/C https://blog.csdn.net/qq_36368339/artic ...
- Codeforces Round #106 (Div. 2) D. Coloring Brackets 区间dp
题目链接: http://codeforces.com/problemset/problem/149/D D. Coloring Brackets time limit per test2 secon ...
随机推荐
- 从池子里的beta看秋香, 个性迥异
从池子里的beta看秋香, 个性迥异 前文里那十只个股为例, 统计了它们的beta值. 回顾如下: Num name code Beta 0 深圳燃气 601139 0.710 公用事业 1 分众传媒 ...
- 使用ResourceBundle读取配置文件
在Java语言中,使用一种以.properties为扩展名的文本文件作为资源文件,该类型的文件的内容格式为类似: 12 #注释语句 some_key=some_value 形式.以#开头的行作为注释行 ...
- IDAPython学习(一)
1.概述 IDAPython在IDA中集成了Python解释器,除了提供了Python功能外,使用这个插件还可以编写实现IDC脚本语言的所有Python脚本. IDAPython显著优势在于,它可以充 ...
- Java SE之向上转型(动态绑定)与向下转型
[Keywords]:向上转型 向下转型 动态绑定[1] 静态绑定[Abstract]:Java调用对象方法时,一般采用运行时绑定机制.[1] 在程序运行时,采用动态绑定意味着:虚拟机 ...
- Python 入门基础19 --面向对象、封装
2019.04.17 一.面向对象与面向过程 二.名称空间操作 三.类与对象的概念 四.语法 五.对象查找属性的顺序 2019.04.18 1.类与对象的所有概念:__init__方法 2.类的方法与 ...
- Maven安装配置操作
1)下载maven安装包并解压: 2)环境变量配置: 3)编辑环境变量Path,追加%MAVEN_HOME%\bin; 4)maven安装配置后进行dos命令检查:在cmd中输入 mvn -v 5)配 ...
- kali linux 下搭建git服务器
参考:http://www.cnblogs.com/dee0912/p/5815267.html https://www.liaoxuefeng.com/wiki/001373951630592960 ...
- 【转】Python流程控制语句
[转]Python流程控制语句 人们常说人生就是一个不断做选择题的过程:有的人没得选,只有一条路能走:有的人好一点,可以二选一:有些能力好或者家境好的人,可以有更多的选择:还有一些人在人生的迷茫期会在 ...
- xargs -i和-I的区别【转】
xargs与find经常结合来进行文件操作,平时删日志的时候只是习惯的去删除,比如 # find . -type f -name "*.log" | xargs rm -rf * ...
- win7安装Ubuntu变双系统以及删除Ubuntu分区操作
Window7系统基础上安装Ubuntu使构成双系统,整个过程如下: 1. 一块空闲磁盘分区准备. “我的电脑”右键 > 管理 > 磁盘管理 > 压缩(从有空余分区压缩)/删除(删除 ...