Renting Boats
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的更多相关文章
- [CareerCup] 15.1 Renting Apartment 租房
Write a SQL query to get a list of tenants who are renting more than one apartment. -- TABLE Apartme ...
- [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 ...
- [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 ...
- Code forces363D Renting Bikes
Renting Bikes Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Subm ...
- 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 ...
- Codeforces Round #211 (Div. 2)-D. Renting Bikes,二分!感谢队友出思路!
D. Renting Bikes 读懂题后一开始和队友都以为是贪心.可是贪心又怎么贪呢..我们无法确定到底能买多少车但肯定是最便宜的前x辆.除了公共预算每个人的钱只能自己用,也无法确定每个人买哪一辆车 ...
- [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 ...
- LeetCode 881. Boats to Save People
原题链接在这里:https://leetcode.com/problems/boats-to-save-people/ 题目: The i-th person has weight people[i] ...
- 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 ...
随机推荐
- Cleaning Shifts(区间覆盖)
/* http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1019&ojid=1&cid=10 题目: 给定一个时 ...
- (组合数学3.1.1.2)UVA 10098 Generating Fast(使用字典序思想产生所有序列)
/* * UVA_10098.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> # ...
- 通配符的匹配很全面, 但无法找到元素 'cache:advice' 的声明
EB-INF\classes\spring-jdbc.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineN ...
- java.lang.NoClassDefFoundError: com/ibatis/sqlmap/engine/mapping/result/BasicResultMap
错误日志: java.lang.NoClassDefFoundError: com/ibatis/sqlmap/engine/mapping/result/BasicResultMap at ...
- nvl,空时的推断和取值
nvl NVL的概念 Oracle/PLSQL中的一个函数. 格式为: NVL( string1, replace_with) 功能:假设string1为NULL,则NVL函数返回replace_wi ...
- VMware于CentOS网络设置
VMware于CentOS网络设置 底: 笔记本电脑有两块网卡: 1. 网卡连接公司内网,仅仅配置了内网ip和子网掩码. 2. 无线网卡.连接4g无线路由器.dhcp自己主动配置. 问题: 在VMwa ...
- Analyzing UI Performance with Systrace 使用systrace工具分析ui性能
While developing your application, you should check that user interactions are buttery smooth, runni ...
- (转)Css样式兼容IE6,IE7,FIREFOX的写法
根据FF和IE对一些符号识别的差异,我们可以单独对FF以及IE定义样式,例子: 区别IE6与FF: background:orange;*background:blue; 区别I ...
- js的异步的问题的再次理解
*js是实实在在的单线程语言,在一小个时刻,在(js的执行对列)只有一个执行,一个没有完,另一个必须等待,什么都不做,只有抖着腿的等; *本来语言本身是同步的,之所以是异步执行,是因为在浏览器环境中, ...
- SQL 生成可配置流水号
需求背景每执行一次方法,根据公式返回最新的流水号.第一次使用时需要先插入一条数据,BizSeqValue 为流水起始号:A2014030000,Formula 为公式:A[yyyy][mm][c4], ...