Lightoj1047——Neighbor House(dp)
来源:互联网 发布:淘宝云客服考试试题 编辑:程序博客网 时间:2024/05/21 02:15
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 B are 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
Output for 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
Case 1: 137
Case 2: 96
要把一排屋子刷成三原色中的一种,要求邻居不能相同
给出每个房子刷三种颜色的费用,求最小费用。
他们都说很简单为什么我就是不会做呢???
#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <cstdio>#include <set>#include <math.h>#include <algorithm>#include <queue>#include <iomanip>#include <map>#define INF 0x3f3f3f3f#define MAXN 105#define Mod 20007using namespace std;int dp[1005][5],r[1005],g[1005],b[1005];int main(){ int t; scanf("%d",&t); for(int cas=1; cas<=t; ++cas) { int n; scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d%d%d",&r[i],&g[i],&b[i]); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;++i) { dp[i][0]=min(dp[i-1][1],dp[i-1][2])+r[i]; dp[i][1]=min(dp[i-1][0],dp[i-1][2])+g[i]; dp[i][2]=min(dp[i-1][0],dp[i-1][1])+b[i]; } printf("Case %d: %d\n",cas,min(dp[n][0],min(dp[n][1],dp[n][2]))); } return 0;}
- Lightoj1047——Neighbor House(dp)
- 【lightoj1047】Neighbor House
- lightOJ 1047 Neighbor House (DP)
- LightOJ - 1217 Neighbor House (II)(dp)
- LightOJ 1047 - Neighbor House(dp)
- LightOJ 1047 - Neighbor House (dp)
- LightOj 1047 Neighbor House(基础dp)
- 【LightOJ】1047 - Neighbor House(dp)
- 【light-oj】-1047 - Neighbor House(dp)
- lightoj 1047 - Neighbor House DP(简单线性DP)
- LightOJ 1047 - Neighbor House 【DP】
- lightoj 1047 Neighbor House(Dp)
- LightOJ - 1047 Neighbor House(DP)
- LightOJ 1047 - Neighbor House(DP)
- lightoj 1047 - Neighbor House DP
- 【 lightoj 1047 - Neighbor House + dp】
- LightOJ 1047 Neighbor House (DP 数字三角形变形)
- Light oj 1217 - Neighbor House (II)(dp)
- wordpress关于插件和主题
- Linux页框分配时,node和zone的选择
- javascript中如何去掉数组中的重复项
- Linux进程描述符:task_struct结构体
- Android中哪里使用到了反射
- Lightoj1047——Neighbor House(dp)
- JedisCluster死活连接不上集群,提示Could not get a resource from the pool
- 登陆界面的密码记住
- Python设计模式(三)--抽象工厂模式
- database基本操作
- c3p0数据源死锁
- myEclipse10编译错误
- iOS开发 网页中的alert/contirm 点击方法未执行
- lintcode——把排序数组转换为高度最小的二叉搜索树