http://acm.hdu.edu.cn/showproblem.php?pid=1260

用dp[i]表示处理到第i个的时候用时最短。

那么每一个新的i,有两个选择,第一个就是自己不和前面的组队,第二就是和前面的组队。

那么dp[i] = min(dp[i - 1] + a[i], dp[i - 2] + b[i]);  前者是自己组队。

边界条件 dp[0] = 0; dp[1] = a[1];

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> const int maxn = + ;
int a[maxn];
int b[maxn];
int dp[maxn];
void work() {
int n;
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (int i = ; i <= n; ++i) {
scanf("%d", &b[i]);
}
dp[] = ;
dp[] = a[];
for (int i = ; i <= n; ++i) {
dp[i] = min(dp[i - ] + a[i], dp[i - ] + b[i]);
}
// cout << dp[n] << endl;
int addHour = dp[n] / / ;
int addMin = (dp[n] / ) % ;
int addSec = dp[n] % ;
printf("%02d:%02d:%02d ", + addHour, addMin, addSec);
if ( + addHour > ) {
printf("pm\n");
} else if ( + addHour == ) {
if (addMin || addSec) {
printf("am\n");
} else printf("pm\n");
} else printf("am\n");
return;
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

HDU 1260 Tickets DP的更多相关文章

  1. 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets

    2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...

  2. HDU 1260 Tickets (普通dp)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others)   ...

  3. Tickets HDU - 1260 水DP

    HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1 ...

  4. HDU 1260 Tickets(简单dp)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  5. HDU - 1260 Tickets 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...

  6. HDU 1260 Tickets(基础dp)

    一开始我对这个题的题意理解有问题,居然超时了,我以为是区间dp,没想到是个水dp,我泪奔了.... #include<stdio.h> #include<string.h> # ...

  7. Tickets HDU - 1260 简单dp

    #include<iostream> using namespace std; const int N=1e5; int T,n; int a[N],b[N]; int dp[N]; in ...

  8. 题解报告:hdu 1260 Tickets

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...

  9. hdu 1260 Tickets

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...

随机推荐

  1. physoft.net网站暂停 www.physoft.cn 正式开通 (菲烁科技, physoft)

    physoft.net原本计划以开源代码为主体,由于各种原因代码未能开源.基于这些代码,physoft成立了 菲烁(重庆)科技有限公司 ( www.physoft.cn) ,专注于工业级双目视觉测量, ...

  2. unity3d mvvm c#

    using UnityEngine; using System.Collections; public interface IState { void BeforEnter(); void Befor ...

  3. 远程调用appium server

    例如:我有两台电脑A(192.168.112.10)和B(192.168.112.11),那我怎么能在A执行本地脚本,但是使用B上的server呢?   查看appium连接appium服务并开启一个 ...

  4. appium 特殊操作

      一.触摸操作   1.driver.tap([坐标],持续点击时间) 除了定位到元素的点击外,也可以通过tab实现坐标的点击 driver.tap(driver.tap([(216,1776)], ...

  5. September Challenge 2017

    Little Chef and Sums 分析:水题,去维护一下前缀和以及后缀和就好,注意long long #include "iostream" #include " ...

  6. TFS 备注

    1,更改任何文件, 先checkout, 再继续更改. 2. 更新sln时, 一定要更新include文件 3. 每次提交代码放到shelf上, 自己本地建立2个workspace, 来进行coder ...

  7. 中国移动推出NB-IoT/eMTC/GSM多模通信模组Qualcomm调制解调器支持

    亚洲电子消费展(CES Asia)在上海举行.期间,中国移动正式推出NB-IoT/eMTC/GSM三模通信模组A9500.该通信模组采用Qualcomm MDM9206 LTE IoT调制解调器,具有 ...

  8. OpenCode:template

    ylbtech-OpenCode: 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbtec ...

  9. 《精通Spring4.X企业应用开发实战》读后感第四章

  10. Redis使用的相关问题

    Redis用那些数据结构? 字符串类型String 字典Hash 列表List 集合Set 有序集合SortedSet HyperLogLog.Geo.Pub/Sub Redis Module.Blo ...