您的位置:首页 > 博客中心 > 互联网 >

PaintHouse I

时间:2022-05-11 13:03

ColorCostDP.hpp

//
// Created by Administrator on 2021/7/21.
//

#ifndef C__TEST01_COLORCOSTDP_HPP
#define C__TEST01_COLORCOSTDP_HPP

#include 

class ColorCostDP {
public:
    ColorCostDP(vector> costN, int N);
    void printData();
    int algorithmDP(vector> &cost, int &N);
private:
    int N;                      // array of bulidings
    vector> cost;
};
ColorCostDP::ColorCostDP(vector> costN, int N):
        cost(costN), N(N)
{
    cost.resize(costN.size());
    for (int i = 0; i < costN.size(); ++i) {
        cost[i].resize(costN.size());
    }
}

void ColorCostDP::printData() {
    for(int i; i> &cost, int &N){
    vector> f;
    f.resize(N+1); //f[1] is the first buliding
    for(int i = 0; i

main.cpp

#include 
using namespace std;

/*
 * 有一排N栋房子,每栋房子要漆成3种颜色中的一种:红蓝绿
任何相邻的两栋房子不能漆成同样的颜色
第i栋房子要染成红色、蓝色和绿色的花费分别为cost[i][0] cost[i][1] cost[i][2]
问最少花多少钱
 例子:
 输入:
 - N = 3
 - Cost = [[14, 2, 11], [11, 14, 5], [14, 3, 10]]
 -输出:10
 * */
#include "ColorCostDP.hpp"

int main() {
    vector> cost = {
            {14, 2, 11},
            {11, 14, 5},
            {14, 3, 10},
    };
    int N = 4;
    ColorCostDP ccdp(cost, N);

    //ccdp.printData();
    int result;
    result = ccdp.algorithmDP(cost, N);

    cout << result << endl;

    return 0;
}

本类排行

今日推荐

热门手游