题目大意:有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. [C++]数组指针与指针数组

    //声明: 1.&----取地址运算符 eg: int m = 1; int *p = &m;//(*p) == m的地址 == &m; 2.*----间接访问运算符 eg: ...

  2. Java SE之基本程序设计结构

     概述:    0.注释    1.基本数据类型(有且仅有8个):         1.1 整型:int,short,long,byte(表示一个字节,[-128,127])          1.2 ...

  3. luogu P3522 [POI2011]TEM-Temperature

    这道题暴力做法就是枚举每个起点,然后向后拓展到不能拓展 就像这样(红框是每个位置的取值范围,绿线是你取的值构成的折线) 应该可以发现,左端点往右移的过程中,右端点也只能不动或往右移,所以我们可以每次移 ...

  4. react框架实现点击事件计数小案例

    下面将以一个小案例来讲解react的框架的一般应用,重点内容在代码段都有详细的解释,希望对大家有帮助 代码块: 代码块: import React from 'react'; import React ...

  5. [转]xargs命令详解,xargs与管道的区别

    为什么要用xargs,问题的来源 在工作中经常会接触到xargs命令,特别是在别人写的脚本里面也经常会遇到,但是却很容易与管道搞混淆,本篇会详细讲解到底什么是xargs命令,为什么要用xargs命令以 ...

  6. JS禁止右键查看源码,禁止复制,复制内容到剪切板

    有时候我们希望自己的网页源码不被查看,这时需要关掉鼠标的右击事件;有时候我们也希望禁止选择页面内容Ctrl+C复制. 1.禁止右键查看源码; <script> //设置右键事件 funct ...

  7. 【CXF】com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Faul

    在客户端生成代码之后测试出现错误: com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Faul ...

  8. Linux定时任务调度

    ⒈概述 任务调度:是指系统在某个时间执行的特定的命令或程序 分类:1)系统任务:有些重要的工作必须周而复始的执行,例如病毒扫描等 2)用户任务:个别用户可能希望定时执行某些程序,例如mysql定时备份 ...

  9. Java探针-Java Agent技术-阿里面试题

    Java探针参考:Java探针技术在应用安全领域的新突破 最近面试阿里,面试官先是问我类加载的流程,然后问了个问题,能否在加载类的时候,对字节码进行修改 我懵逼了,答曰不知道,面试官说可以的,使用Ja ...

  10. python 内置函数总结(大部分)

    python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...