LightOj 1047 Neighbor House(基础dp)

飞牛NAS一键部署小雅Emby全家桶:解锁海量影音资源与智能刮削 本文详细介绍了如何在飞牛NAS上通过Docker一键部署小雅Emby全家桶,完美解决传统WebDAV挂载无法刮削元数据的问题。该方案整合了小雅Alist海量影音资源与Emby媒体服务器,通过预下载超百GB元数据包,自动实现海报、简介等信息的完美匹配,打造出精美的个人影音库。部署过程需准备阿里云盘令牌与充足存储空间,并详解了从环境配置、镜像拉取到最终验证的完整步骤及优化技巧。 阅读详情

Neighbor House

Description

The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They've also decided that no two neighboring houses will be painted the same color. The neighbors of house i are houses i-1 and i+1. The first and last houses are not neighbors.

You will be given the information of houses. Each house will contain three integers "R G B" (quotes for clarity only), where R, G and Bare the costs of painting the corresponding house red, green, and blue, respectively. Return the minimal total cost required to perform the work.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case begins with a blank line and an integer n (1 ≤ n ≤ 20) denoting the number of houses. Each of the next n lines will contain 3 integers "R G B". These integers will lie in the range [1, 1000].

Output

For each case of input you have to print the case number and the minimal cost.

Sample Input

2

4

13 23 12

77 36 64

44 89 76

31 78 45

3

26 40 83

49 60 57

13 89 99

Sample Output

Case 1: 137

Case 2: 96


解题思路:

有n个房子,每个房子都可以染红绿蓝三种颜色,并且给出了每个房子染每种颜色费用,相邻房子不能同色,求染完所以房子的最小

费用。

设dp[i][j]就是第i个房子染第j个颜色后的最小费用。

因此:ans=min{dp[n][i],i∈[0,3]}。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int cost[25][3];
int dp[25][3];

int main(){
    int T,t = 1;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        memset(dp,0x3f3f3f3f,sizeof(dp));
        for(int i = 1; i <= n; i++)
            scanf("%d%d%d",&cost[i][0],&cost[i][1],&cost[i][2]);
        dp[1][0] = cost[1][0];
        dp[1][1] = cost[1][1];
        dp[1][2] = cost[1][2];
        for(int i = 2; i <= n; i++){
            dp[i][0] = min(dp[i-1][1],dp[i-1][2])+cost[i][0];
            dp[i][1] = min(dp[i-1][0],dp[i-1][2])+cost[i][1];
            dp[i][2] = min(dp[i-1][0],dp[i-1][1])+cost[i][2];
        }
        int ans = min(dp[n][0],min(dp[n][1],dp[n][2]));
        printf("Case %d: %d\n",t++,ans);
    }
    return 0;
}


ZY1-02D (ZY1E)多光谱数据预处理 资源一号02D卫星(5米光学卫星)于2019年9月12日成功发射,卫星搭载的两台相机,可有效获取115公里幅宽的9谱段多光谱数据以及60公里幅宽的166谱段高光谱数据,其中全色谱段分辨率可达2.5米、 多光谱为10米、高光谱优于30米,高光谱载荷可见近红外和短波红外光谱分辨率分别达到10纳米和20纳米。 阅读详情

相关推荐

Intouch间接变量(扩展)

间接变量只是Intouch提供给开发者的便捷方式之一,并不是所有情况都一定要使用间接变量,有时候用条件语句或者内存变量的方式也能起到类似的作用。

weixin_41571357的博客 2167

Light OJ 1047 Neighbor House(简单DP)

题意:房子排成一排,每个房子可以涂三种颜色,每个房子涂一种颜色对应一个花费,相邻房子不能同色。问最少花费。 解析不写了。 [code]: #include #include #include using namespace std; typedef long long LL; int n,dp[50][3],a[50][3]; int main(){ int i,j,k,cas

Neutralzz的博客 351

keil自动分配SDRAM空间设置使用

1.修改.sct文件。

qizhi321123的博客 1404

Neighbor House LightOJ - 1047

The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They've also decided that no two neighboring houses will be painted the same color. The neighbors of house i a...

weixin_30249203的博客 173

VSCode上搭建C/C++开发环境(vscode配置c/c++环境)Windows系统---保姆级教程

关于VSCode上搭建C/C++开发环境的内容,到这里就结束了,这里博主感叹一下,VSCode真的挺强大的,作为一个编辑器,可以通过和编译器链接成为开发环境,将环境配置好的话,在这上面写代码似乎也是个不错的选择。大家有任何疑问,欢迎在评论区中提出,本篇博客有任何问题和错误也欢迎来和博主讨论,真心希望能和大家一起进步。最后,如果本篇博客对你有帮助的话,能不能给博主一个三连啊!

2303_79329831的博客 8万+

Linux【实战】—— LAMP环境搭建 & 部署网站

由LinuxApacheMySQLPHP组成的一个web网络平台。

2201_75935630的博客 4980

LightOJ 1047 - Neighbor House(dp)

题目链接:LightOJ 1047 - Neighbor House代码#include <cstdio> #include <cstring> #include <algorithm>using namespace std; const int maxn = 30; const int inf = 0x3f3f3f3f;int N, dp[maxn][3];int main () { in

不慌不忙、不急不躁 604

【OpenClaw企业级智能体实战】第04篇:OpenClaw成本优化实战——Token消耗降96%!claude-mem+OpenViking从入门到精通

OpenClaw作为企业级智能体框架,凭借强大的自动化能力成为企业数字化转型的热门工具,但原生机制导致的上下文冗余问题,让众多用户面临“Token消耗失控”的困境——单周账单数千元的案例屡见不鲜。本文基于阿里云实测数据与开源工具官方文档,先深度拆解OpenClaw成本黑洞的核心成因(记忆碎片化、Token指数级膨胀),再系统讲解两款核心优化工具(claude-mem单Agent记忆管理、OpenViking多Agent集群底座)的底层原理、算法架构与实现逻辑,提供从环境搭建、工具集成、参数调优到安全部署

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 702

【lightoj1047】Neighbor House

1047 - Neighbor House PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB The people of Mohammadpur have decided to paint each ofth

better_space的博客 403

畅游Diffusion数字人(0):专栏文章导航

畅游Diffusion数字人(0):专栏文章导航

沉迷单车的追风少年 1418

92. SAP ABAP 系统里长文本 Long Text 的设计和读取函数 READ_TEXT 的详细讲解

SAP ABAP中的长文本(Long Text)是指在SAP系统中存储和管理较长文本信息的一种机制。长文本通常用于存储描述性信息、注释、说明等,这些文本信息可能超过了标准数据库表字段的长度限制。 长文本的作用主要有以下几点: 1. 更多的信息存储:长文本允许您存储和显示比标准表字段允许的更多信息。例如,产品描述、用户注释、维护计划等可能需要大量的文本来详细描述。 2. 更好的可读性:长文本提供了更好的文本格式化选项,可以改善可读性。用户可以使用段落、列表、字体样式等格式化文本,以便更容易地理解和阅读。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1993

Neighbor House LightOJ - 1047(线性 dp)

题目链接 题意 每个房子可以染成 r、g、b 三种颜色,染成对应的颜色有对应的花费。先在要 n 个相邻的房子染成颜色,并且要求相邻的房屋不能染成相同的颜色,问把所有的房子都染了合适的颜色之后的最小总花费是多少? 思路 设 dp [i][x] 前 i 个房子染完颜色,且第 i 个房子染成 x 颜色的最小花费。 dp [i][x] 可以从 dp [i][y] 进行转移,当(x != y)的时候 #include <bits/stdc++.h> using namespace std; #d

做一只熊猫不好吗? 188

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LightOJ 1047 - Neighbor House 【DP】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1047 题意:求(p[i][j])上下相邻的 j 不能相同的数塔的最小和。 解法:看代码! 代码:#include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include

mfcheer 679

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

【LightOJ】1047 - Neighbor House(dp)

点击打开题目 1047 - Neighbor House     PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB The people of Mohammadpur have decided to pa

wyg1997 628

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

lightoj 1047 - Neighbor House DP(简单线性DP)

1047 - Neighbor House     PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB The people of Mohammadpur have decided to paint each of

K键盘里的青春K 632

【 lightoj 1047 - Neighbor House + dp】

Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They’ve also decided that no two neighboring houses will be painted the same color. The neighbors

楚江枫 801

LightOJ 1047 - Neighbor House(DP)

题意:n个房子涂色,相邻须不同色。涂色有不同花费,求最小花费。 思路:dp[i][now][last]表示到第i个房子,现在涂now色,上一次涂last色的最小花费。 代码略长,但意思比较清楚。 #include #include #include #include #include #include #include #include #include #include

ACMiao的博客 495

lightOJ 1047 Neighbor House (DP)

题目链接:lightOJ 1047 Neighbor House 题意:有N做房子,每个房子涂3种颜色各有一个花费,相邻的房子颜色不能一样,给N个房子涂颜色,问完成这个任务的最小花费。 dp[i][j] 表示涂到第i个房子涂j颜色的最小花费。 状态转移方程:dp[i][k]=min(dp[i][k],dp[i-1][j]+p[i].c[k]); AC代码: #

n-1 657

lightoj 1047 Neighbor House(Dp)

思路:定义dp[i][j] 为粉刷第i个房子用的颜色j dp[i][j] = min(dp[i-1][(j+1)%3] , dp[i-1][(j+2) % 3]); 一共有三种颜色{0, 1, 2},任取一种颜色{j},那么和颜色j不同的颜色就为{(j + 1) % 3 , (j + 2) % 3}; /********************************************

fisty 1514

lightOJ 1047 Neighbor House (DP)

lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/C 题目: Description The people of Mohammadpur have decided to paint each of their hous...

weixin_34292959的博客 72

LightOJ 1047 Neighbor House (DP 数字三角形变形)

1047 - Neighbor House PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB The people of Mohammadpur have decided to paint each ofth

ysCover 841

lightoj 1047 - Neighbor House DP

有n个房子,每个房子都可以染红绿蓝三种颜色,并且给出了每个房子染每种颜色费用,相邻房子不能同色,求染完房子的最小费用。 dp[i][j]就是第i个房子染第j个颜色后的总费用。简单的DP.. #include using namespace std; #define ll long long #define N 1005 int dp[N][3],R[N],G[N],B[N]; int main

505

Lightoj1047——Neighbor House(dp)

The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They’ve also decided that no two neighboring houses will be painted the same color. The neighbors of house i ar

Beyond the Sora 904

LightOJ 1047 - Neighbor House (dp)

题意: n<=20个房子涂3色,每个房子涂不同颜色代价不用,相邻房子颜色不能相同,求涂完的最小代价n<=20个房子涂3色, 每个房子涂不同颜色代价不用, 相邻房子颜色不能相同, 求涂完的最小代价 分析: 煞笔题,dp[i][j]:=前i个房子涂完,且第i个房子颜色为j的最小代价煞笔题, dp[i][j]:= 前i个房子涂完, 且第i个房子颜色为j的最小代价 ans=min{dp[n][

TaoSama's Microcosm 545

lightoj-1047-Neighbor House【矩阵DP】

题目链接:点击打开链接 1047 - Neighbor House     PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB The people of Mohammadpur have decided to

_Somethingwill 415

lightoj-1047 - Neighbor House(简单的线性dp)

1047 - Neighbor House PDF (English) Statistics ForumTime Limit: 0.5 second(s) Memory Limit: 32 MBThe people of Mohammadpur have decided to paint each of their houses red, green, or blue. The...

163
上一篇: HYSBZ 1090 字符串折叠(区间dp)
下一篇: SPOJ GSS3 Can you answer these queries III(线段树)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值