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. 《A First Course in Probability》-chaper8-极限定理-各类不等式

    詹森不等式: 证明:

  2. TCP内核源码分析笔记

    Table of Contents 1 术语 1.1 ABC 1.2 SACK 1.3 D-SACK 1.4 FACK 1.5 F-RTO 1.6 nagle算法 1.7 cork算法 1.8 tem ...

  3. Dolls - 4160(简单二分图匹配)

    题意:有一些箱子,大箱子可以套小箱子,但是必须h>h,w>w,l>l,求出来最外面能剩下几个箱子无法被嵌套.   分析:思考每个箱子都只会被别的箱子套一次,所以构成一二分匹配模型,只 ...

  4. Oracle Locks之DML锁

    Oracle通过锁来实现数据库的并发控制 Oracle Database automatically locks a resource on behalf of a transaction to pr ...

  5. springmvc框架原理分析

    第一步:用户发起请求到前端控制器(DispatcherServlet) 第二步:前端控制器请求HandlerMapping查找Handler,可以根据xml配置,注解进行查找 第三步:处理器映射器Ha ...

  6. Android的adb命令使用以及在DOS的一系列操作

    adb是什么?:adb的全称为Android Debug Bridge,就是起到调试桥的作用.      adb有什么用?:借助adb工具,我们可以管理设备或手机模拟器的状态.还可以进行很多手机操作, ...

  7. Spark GraphX的函数源码分析及应用实例

    1. outerJoinVertices函数 首先给出源代码 override def outerJoinVertices[U: ClassTag, VD2: ClassTag] (other: RD ...

  8. 融云的Java端实现

    产品中要使用融云实现即时通讯,下面是实现步骤: 1 .注册appkey secret,这个是第一步: 2 .下载融云Java客户端 https://github.com/rongcloud/serve ...

  9. Team Foundation Server 2013 with Update 3 Install LOG

    [Info   @10:14:58.155] ====================================================================[Info   @ ...

  10. Could not fetch https://api.github.com/repos/RobinHerbots/jquery

    使用 composer 安装YII2时, 如题所示提示, 原因是由于yii安装中, 需要有一些相关的认证[或许说是composer的认证], 如有如下提示 Could not fetch https: ...