题目大意:有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的更多相关文章

  1. 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 ...

  2. Codeforces Round #369 (Div. 2) C. Coloring Trees 动态规划

    C. Coloring Trees 题目连接: http://www.codeforces.com/contest/711/problem/C Description ZS the Coder and ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #369 (Div. 2) C. Coloring Trees(简单dp)

    题目:https://codeforces.com/problemset/problem/711/C 题意:给你n,m,k,代表n个数的序列,有m种颜色可以涂,0代表未涂颜色,其他代表已经涂好了,连着 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #106 (Div. 2) D. Coloring Brackets 区间dp

    题目链接: http://codeforces.com/problemset/problem/149/D D. Coloring Brackets time limit per test2 secon ...

随机推荐

  1. CopyFromScreen在屏幕缩放情况下需要做处理

    using System; using System.Drawing; using System.Runtime.InteropServices; //这段代码转自网上 namespace Syste ...

  2. shell反弹总结

    NC反弹 常用的命令: -l   监听模式 -n 指定数字的IP地址 -p   port(本地端口) -s addr 本地源地址 -v 详细输出 -i secs 延时的间隔 -e  filename  ...

  3. Leanote 蚂蚁笔记 云笔记

    Leanote 蚂蚁笔记  1.Leanote 数据存储是使用mongo存放的,所以需要安装mongo包 1.MongoDB 数据存储 Leanote 依赖 MongoDB 作为数据存储,下面开始安装 ...

  4. python2的比较函数,cmp

    class Shu(object): def __init__(self,ss): self.ss = ss def __str__(self): return '(%s: %s)' % (self. ...

  5. MGR架构~单写模式架构的搭建

    一 简介 :MGR一直没有时间测试,今天咱们来初步了解搭建一下呗 二 环境: mysql5.7.20  单台机器 启动三实例 三  mysql 搭建: 1 建立相关目录+ mkdir -p /data ...

  6. 2017-2018-2 20155303『网络对抗技术』Exp4:恶意代码分析

    2017-2018-2 20155303『网络对抗技术』Exp4:恶意代码分析 --------CONTENTS-------- 一.原理与实践说明 1.实践目标 2.实践内容概述 3.基础问题回答 ...

  7. Pytorch 入门之Siamese网络

    首次体验Pytorch,本文参考于:github and PyTorch 中文网人脸相似度对比 本文主要熟悉Pytorch大致流程,修改了读取数据部分.没有采用原作者的ImageFolder方法:   ...

  8. C++ 字符串的编码

    转载链接:https://www.cnblogs.com/akb48/p/5439154.html windows平台 char 表示单字符,占用一个字节 wchar_t 表示宽字符,占用两个字节 L ...

  9. Class create, device create, device create file【转】

    来自:http://www.hovercool.com/en/Class_create,_device_create,_device_create_file 开始写Linux设备驱动程序的时候,很多时 ...

  10. /etc/fstab文件详解【转】

    ******************************************************************************* 有很多人经常修改/etc/fstab文件 ...