题目链接:

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;
}

  

poj-2336 Ferry Loading II(dp)的更多相关文章

  1. poj 2336 Ferry Loading II ( 【贪心】 )

    Ferry Loading II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3704   Accepted: 1884 ...

  2. POJ 2609 Ferry Loading(双塔DP)

    Ferry Loading Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1807   Accepted: 509   Sp ...

  3. POJ-2336 Ferry Loading II(简单DP)

    Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3763 Accepted: 1919 Desc ...

  4. TOJ 2419: Ferry Loading II

    2419: Ferry Loading II  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal Subm ...

  5. POJ 2609 Ferry Loading

    双塔DP+输出路径. 由于内存限制,DP只能开滚动数组来记录. 我的写法比较渣,但是POJ能AC,但是ZOJ依旧MLE,更加奇怪的是Uva上无论怎么改都是WA,其他人POJ过的交到Uva也是WA. # ...

  6. [POJ2336]Ferry Loading II

    题目描述 Description Before bridges were common, ferries were used to transport cars across rivers. Rive ...

  7. AtCoder - agc043_a 和 POJ - 2336 dp

    题意: 给你一个n行m列由'#'和'.'构成的矩阵,你需要从(1,1)点走到(n,m)点,你每次只能向右或者向下走,且只能走'.'的位置. 你可以执行操作改变矩阵: 你可以选取两个点,r0,c0;r1 ...

  8. Ferry Loading III[HDU1146]

    Ferry Loading IIITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

随机推荐

  1. java 中 instanceof 和 isInstance区别

    两者的功能是等价的.区别: 1.instanceof 是一个操作符(类似new, ==等): 使用方法: if (ins instanceof String) { //logic } 2.isInst ...

  2. INSTALL_FAILED_UID_CHANGED解决的方法

    近期开发过程中又遇到了这个问题,最终找到了一个比較好的解决的方法.在此记录下. 打开手机或者pad中的设置----->安全----->未知来源(同意安装非安卓市场应用程序). 把这个取消, ...

  3. 使用java+TestNG进行接口回归测试

    TestNG是一个开源自动化测试框架,“NG”表示下一代(Next Generation的首字母). TestNG类似于JUnit(特别是JUnit 4),但它不是JUnit框架的扩展,相较于Juni ...

  4. apt-mirror 校验错误文件处理

    apt-mirror是一个用来将Debian或Ubuntu的软件源镜像到本地的工具,这个工具工作得非常好,不过有的时候由于网络问题,会有一些文件的校验是失败的,但apt-mirror并不能发现,等到最 ...

  5. Python,Pycharm,Anaconda等的关系与安装过程~为初学者跳过各种坑

    1.致欢迎词 我将详讲讲述在学Python初期的各种手忙脚乱的问题的解决,通过这些步骤的操作,让你的注意力集中在Python的语法上以及后面利用Python所解决的项目问题上.而我自己作为小白,很不幸 ...

  6. nginx配置1:借助Nginx搭建反向代理服务器与缓存静态文件

    修改配置文件nginx.conf (1)进程数与每个进程的最大连接数: •nginx进程数,建议设置为等于CPU总核心数 •单个进程最大连接数,那么该服务器的最大连接数=连接数*进程数 (2)Ngin ...

  7. sqlite3常用操作命令 和mysql的区别及优缺点

    SQLite 的数据库权限只依赖于文件系统,没有用户帐户的概念. sqlite3 testdb.db .databases 命令查看数据库列表 create table tbl(name char(1 ...

  8. IOS --支付宝SDK 分解讲解

    开发在手机端的时候(客户端),我们主要负责客户端(手机端)的开发,所以那些繁琐的到支付宝官网填写商户信息可以留给后台去弄,后台只要把: 1回调地址, 2app的ID, 3商户的私钥(privateKe ...

  9. python scrapy爬虫框架

    http://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/tutorial.html scrapy 提取html的标签内容 from scrapy.selec ...

  10. Android 超高仿微信图片选择器 图片该这么载入

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/39943731,本文出自:[张鸿洋的博客] 1.概述 关于手机图片载入器,在当今像 ...