题目链接:

Ferry Loading II

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3946   Accepted: 1985

Description

Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by the river's current. Cars drive onto the ferry from one end, the ferry crosses the river, and the cars exit from the other end of the ferry. 
There is a ferry across the river that can take n cars across the river in t minutes and return in t minutes. m cars arrive at the ferry terminal by a given schedule. What is the earliest time that all the cars can be transported across the river? What is the minimum number of trips that the operator must make to deliver all cars by that time?

Input

The first line of input contains c, the number of test cases. Each test case begins with n, t, m. m lines follow, each giving the arrival time for a car (in minutes since the beginning of the day). The operator can run the ferry whenever he or she wishes, but can take only the cars that have arrived up to that time.

Output

For each test case, output a single line with two integers: the time, in minutes since the beginning of the day, when the last car is delivered to the other side of the river, and the minimum number of trips made by the ferry to carry the cars within that time.

You may assume that 0 < n, t, m < 1440. The arrival times for each test case are in non-decreasing order.

Sample Input

2
2 10 10
0
10
20
30
40
50
60
70
80
90
2 10 3
10
30
40

Sample Output

100 5
50 2

题意:

给m辆车的到达岸边的时间,现在给你一个轮渡能运车的数量,和单程的时间,现在问把这些车运过去的最短时间是多少,在这个时间中的 最少运送次数是多少?

思路:

dp[i]表示运送前i个要用的时间,num[i]表示在dp[i]的时间内的最少次数;相邻的车在一块运,转移方程看代码吧;

AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack>
#include <map>using namespace std;#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));typedef  long long LL;template<class T> void read(T&num) {char CH; bool F=false;for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {if(!p) { puts("0"); return; }while(p) stk[++ tp] = p%10, p/=10;while(tp) putchar(stk[tp--] + '0');putchar('\n');
}const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=2e3+14;
const double eps=1e-12;int a[maxn],dp[maxn],num[maxn];int main()
{int T;read(T);while(T--){int n,m,t;read(n);read(t);read(m);For(i,1,m)read(a[i]);For(i,1,m)dp[i]=inf,num[i]=0;dp[0]=0;num[0]=0;For(i,1,m){for(int j=max(0,i-n);j<i;j++){if(j==0){dp[i]=a[i]+t,num[i]=1;continue;}if(dp[i]>max(dp[j]+t,a[i])+t)dp[i]=max(dp[j]+t,a[i])+t,num[i]=num[j]+1;else if(dp[i]==max(dp[j]+t,a[i])+t)num[i]=min(num[i],num[j]+1);}}cout<<dp[m]<<" "<<num[m]<<"\n";}return 0;
}

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5754980.html

poj-2336 Ferry Loading II(dp)相关推荐

  1. POJ 2336 Ferry Loading II 动态规划

    题意:一个渡河问题,船每次最多可以载n辆车,单程渡河的时间是t,有m辆车要渡河,问最少时间把所有车运过河去的时间是多少,这个情况下,最少的运输次数是多少. 分析:确实是动态规划,惭愧我想了很久,也没想 ...

  2. 目的地返回POJ 2336 动态规划(DP) Ferry Loading II

    在写这篇文章之前,xxx已写过了几篇关于改目的地返回主题的文章,想要了解的朋友可以去翻一下之前的文章 标题链接:http://poj.org/problem?id=2336 分析:想设我们要求的是第i ...

  3. ACM HEU OJ 1019 Ferry Loading II || POJ 2336

    题意:摆渡问题,一个船一次最多能运送n辆汽车.现有m辆汽车需要运送,运输一次的时间为t,求出运送完所有的汽车后的最小时间以及最小的运输次数. 贪心思想:如果m%n==0则运输m/n次 反之则运输 m+ ...

  4. HDOJ 5087 Revenge of LIS II DP

    HDOJ 5087 Revenge of LIS II DP DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS ...

  5. POJ 2955 Brackets (区间DP)

    题目链接:http://poj.org/problem?id=2955 Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  6. poj 3071 Football(概率dp)

    http://poj.org/problem? id=3071 大致题意:有2^n个足球队分成n组打比赛.给出一个矩阵a[][],a[i][j]表示i队赢得j队的概率.n次比赛的流程像这样France ...

  7. poj 2817 WordStack (状态dp)

    http://poj.org/problem?id=2817 这个题的意思是第一行给出case数N (1 <= N <= 10),然后给出N个单词,每个一行,当输入不是正整数的时候结束.每 ...

  8. POJ 3280 Cheapest Palindrome(DP 回文变形)

    题目链接:http://poj.org/problem?id=3280 题目大意:给定一个字符串,可以删除增加,每个操作都有代价,求出将字符串转换成回文串的最小代价 Sample Input 3 4 ...

  9. CodeForces - 1480D2 Painting the Array II(dp)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,现在要求拆分成两个子序列,使得两个子序列的贡献之和最 小.对于一个序列的贡献就是,去掉相邻且相同的字母后的长度,即 ∑i=1n[a[i]! ...

最新文章

  1. 分布式链路追踪zipkin
  2. Py之MT:Multithreaded的简介、引入、使用方法之详细攻略
  3. Linux和optee双系统中1020-1023号的中断号的使用
  4. 人工智能助力生命科学新发展 | 飞桨博士会第十一期
  5. 怎么改变表单option标签直接字体大小_不起眼却非常重要的表单交互
  6. 设计师需要的素材网站,给你归纳好了,拿走!
  7. 赛锐信息:SAP系统用户账号类型介绍
  8. 在线段裁剪算法中是否能对区域编码算法进行优化实现模式的唯一判别呢
  9. HashMap遍历有序性问题——map.entrySet()的无序性
  10. Git最好的CRLF(回车,换行)处理策略是什么?
  11. Windows XP 开机优化
  12. Centos7 完全卸载MySQL8.0
  13. 计算机软件cae,各种CAE软件介绍
  14. Oracle DG Broker 进行 SwitchOver Failover,Failover后恢复主从同步
  15. Linux_clustalW安装及使用(部分)
  16. Android API 中文(13) —— ToggleButton
  17. 计算机英语合成词大全,常用的英语合成词大全
  18. autoCAD 创建对象 使用面域 创建图案填充
  19. TikTok营销策略 如何打造TikTok爆款视频?
  20. 有计算机考试励志的文案,写给所有考生的励志文案:心有所期,全力以赴,定有所成...

热门文章

  1. Check failed: error == cudaSuccess (74 vs. 0) misaligned address
  2. vegas9.0合成计时器
  3. ADO连接ACCESS数据库
  4. Leetcode题库263.丑数(c实现)
  5. 1.2 torch_数据预处理
  6. 4-希尔排序C实现(递增递减的简单转换)
  7. python怎么定义文档的行数_python删除文本中行数标签的方法
  8. Django框架(十八)—— auth框架:用户登录、注册、认证
  9. Round A - Kick Start 2019
  10. JSON.stringify时间的问题