算法题:地铁站建站最小花费
来源:互联网 发布:网络嗅探器绿色版 编辑:程序博客网 时间:2024/04/29 14:30
There are total N stations in a Metro Line.Those stations can be divided into three types: U(ground),D(underground) and C(composite).The construction cost of each station differs throughout the Metro Line. It should be noted that the adjacent station type can not be repeated. Given the construction costs of three types for each station,you are required to find out the minimum cost of constructing this Metro Line.For example,
UDCStation1199Station2919Station3991The minimum cost is:1+1+1=3.#include <iostream>#include <math.h>using namespace std;#define N 3int minCost(int i,int j,int *p){ int result=*(p+i*3+j); if(i<N-1) { result+=min(minCost(i+1,(j+1)%3,p), minCost(i+1,(j+2)%3,p)); } return result;}int main(){ int stationCost[N*3]={1,9,9,9,1,9,9,9,1}; int a=minCost(0,0,stationCost); int b=minCost(0,1,stationCost); int c=minCost(0,2,stationCost); int result=min(min(a,b),c); cout<<result<<endl; return 0;}
0 0
- 算法题:地铁站建站最小花费
- 最小花费(图论算法)
- 最小花费
- 最小花费
- 最小花费
- 最小花费
- 最小花费
- 最小花费
- 最小花费
- 最小花费
- 最小花费
- 计算地铁族的来月出行计划对应的月票预支付最小花费
- prime算法-畅通工程之局部最小花费问题.cpp
- 最小花费问题 (最短路径算法)
- 畅通工程之局部最小花费问题(prime算法)
- ccf-csp之地铁修建(最小堆dijkstra算法)
- 题目1086:最小花费
- OJ_1086 最小花费
- 数组克隆及对象的深、浅克隆(deep clone、shallow clone)
- 宏定义
- 集线器与网桥工作原理
- WebKit for Developers
- 使用 Intel HAXM 为 Android 模拟器加速
- 算法题:地铁站建站最小花费
- MP算法和OMP算法及其思想
- 好玩的东西
- IOS用CGContextRef画各种图形
- 数据结构(C语言版)摘录--图
- 装饰者模式
- UNIX Network Programming笔记之第十一章(二)
- 二进制操作
- 帧、行、场