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 ...
随机推荐
- android webview load 本地文件需要注意的地方
记得在工程的main下必须是assets文件夹. 而webview.loadUrl时 必须是 android_asset 必须这样对应,否则无法加载本地html. 具体原因只能在深入学习后再总结了 ...
- [Audio processing] FFMPEG转音频格式和采样率
利用FFMPEG转音频格式和采样率 import os import string import subprocess as sp #Full path of ffmpeg FFMPEG_BIN = ...
- 360. Sort Transformed Array
一元二次方程...仿佛回到了初中. 主要看a的情况来分情况讨论: =0,一次函数,根据b的正负单调递增递减就行了. <0,凸状..从nums[]左右两边开始往中间一边比较一边 从右往左 放: 0 ...
- windows设置多长时间后自动关机 分类: windows常用小技巧 2014-04-15 09:35 230人阅读 评论(0) 收藏
分二步: 第一步:点击windows键,在"搜索程序和文件"的文本框输入:cmd 第二步:输入:shutdown -s -t (设置电脑一小时后自动关机) 备注: ...
- IOS UIView 之属性篇
UIView 继承于UIResponder 所遵守的协议有 NSCoding .UIAppearance. UIAppearanceContainer ...
- 如何看懂Code128条形码
条形码就是我们看到的商品上有的那些竖条条. 要不是项目上用到这个或许我一辈子也不会对那个感兴趣. 条形码其实是分成很多类的,虽然他们看起来都差不多…… 常见的条形码的码制被称为39码.128码.417 ...
- Effective C++ 总结(一)
一.让自己习惯C++ 条款01:视C++为一个语言联邦 为了更好的理解C++,我们将C++分解为四个主要次语言: C.说到底C++仍是以C为基础.区块,语句,预处理器,内置数据类型, ...
- http状态码对应表
http状态码 1**:请求收到,继续处理 2**:操作成功收到,分析.接受 3**:完成此请求必须进一步处理 4**:请求包含一个错误语法或不能完成 5**:服务器执行一个完全有效请求失败 100— ...
- 图片预览(base64和blob:图片链接)和ajax上传、下载(带进度提示)
直接上代码 html和js <!DOCTYPE html> <html> <head> <meta name="viewport" con ...
- git 取消/添加 某文件的跟踪
如果我们不小心将某个文件加入了 git 版本控制,但是突然又不想继续跟踪控制这个文件了,怎么办呢? 使用 git update-index 即可. 不想继续追踪某个文件 git update-inde ...