Description

长江游艇俱乐部在长江上设置了n 个游艇出租站1,2,…,n。游客可在这些游艇出租站租用游艇,并在下游的任何一个游艇出租站归还游艇。游艇出租站i 到游艇出租站j 之间的租金为r(i,j),1< =i< j < =n。试设计一个算法,计算出从游艇出租站1 到游艇出租站n 所需的最少租金。

Input

第1 行中有1 个正整数n(n<=200),表示有n个游艇出租站。接下来的n-1 行是r(i,j),1< =i< j < =n。

Output

从游艇出租站1 到游艇出租站n所需的最少租金

Sample Input

3

5 15

7

Sample Output

12

本题为动态规划问题,运用floyd算法

 #include<stdio.h>
int f[][],n,i,j,k,p,tmp;
void solve()
{
for(k=;k<n;k++)
for(i=;i<n-k;i++)
{
j=i+k;
for(p=i+;p<j;p++)
{
tmp=f[i][p]+f[p][j];
if(f[i][j]>tmp)
f[i][j]=tmp;
}
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
{
for(j=i+;j<n;j++)
scanf("%d",&f[i][j]);
}
solve();
printf("%d\n",f[][n-]);
}
return ;
}

Renting Boats的更多相关文章

  1. [CareerCup] 15.1 Renting Apartment 租房

    Write a SQL query to get a list of tenants who are renting more than one apartment. -- TABLE Apartme ...

  2. [Swift]LeetCode881. 救生艇 | Boats to Save People

    The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat c ...

  3. [Leetcode 881]船救人 Boats to Save People 贪心

    [题目] The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each b ...

  4. Code forces363D Renting Bikes

    Renting Bikes Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Subm ...

  5. 881. Boats to Save People

    The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat c ...

  6. Codeforces Round #211 (Div. 2)-D. Renting Bikes,二分!感谢队友出思路!

    D. Renting Bikes 读懂题后一开始和队友都以为是贪心.可是贪心又怎么贪呢..我们无法确定到底能买多少车但肯定是最便宜的前x辆.除了公共预算每个人的钱只能自己用,也无法确定每个人买哪一辆车 ...

  7. [LeetCode] 881. Boats to Save People 渡人的船

    The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat c ...

  8. LeetCode 881. Boats to Save People

    原题链接在这里:https://leetcode.com/problems/boats-to-save-people/ 题目: The i-th person has weight people[i] ...

  9. LC 881. Boats to Save People

    The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat c ...

随机推荐

  1. 【最小生成树】新的开始(newstart) 解题报告

    [题目描述] 发展采矿业当然首先得有矿井, 小FF花了上次探险获得的千分之一的财富请人在岛上挖了n口矿井, 但他似乎忘记考虑的矿井供电问题…… 为了保证电力的供应, 小FF想到了两种办法: 在这一口矿 ...

  2. @property 的本质是什么?ivar、getter、setter 是如何生成并添加到这个类中的

    出题者简介: 孙源(sunnyxx),目前就职于百度 整理者简介:陈奕龙(子循),目前就职于滴滴出行. 转载者:豆电雨(starain)微信:doudianyu @property 的本质是什么? @ ...

  3. 英蓓特Mars board的android4.0.3源码编译过程

    英蓓特Mars board的android4.0.3源码编译过程 作者:StephenZhu(大桥++) 2013年8月22日 若要转载,请注明出处 一.编译环境搭建及要点: 1. 虚拟机软件virt ...

  4. Web前端之HTML

    一. HTML介绍: 1.HTML:超文本标记语言. 2.HTML是由:标签和内容构成. 3.程序语言有两种:解释性语言(HTML.PHP.Python.Javascript)和编译型语言(C.C++ ...

  5. README 语法编写

    推荐一个超棒的软件 haroopad Standard Markdown \ backslash ` backtick * asterisk _ underscore {} curly braces ...

  6. mybatis logback打印sql

    <?xml version="1.0" encoding="UTF-8" ?><configuration> <contextNa ...

  7. PL/SQL 9.0工具技巧

    1. 设置自动替换 tools--preferences--User interface--Editor--Autoreplace 2.

  8. ./filezilla: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

    opensuse系统 在filezilla官网下载压缩文件解压运行后报 ./filezilla: error while loading shared libraries: libpng12.so.0 ...

  9. digoal -阿里云postgrel大神

    https://yq.aliyun.com/users/1384833841157402?spm=5176.100239.blogrightarea51131.3.T5LRsF

  10. Java基础知识强化之集合框架笔记07:Collection集合的遍历之迭代器遍历

    1. Collection的迭代器: Iterator iterator():迭代器,集合的专用遍历方式 2. 代码示例: package cn.itcast_03; import java.util ...