[kuangbin带你飞]专题十二 基础DP1 H - Tickets HDU - 1260

news/2024/11/28 7:39:00/

题目描述

 Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.
A good approach, reducing the total time of tickets selling, is let adjacent people buy tickets together. As the restriction of the Ticket Seller Machine, Joe can sell a single ticket or two adjacent tickets at a time.
Since you are the great JESUS, you know exactly how much time needed for every person to buy a single ticket or two tickets for him/her. Could you so kind to tell poor Joe at what time could he go back home as early as possible? If so, I guess Joe would full of appreciation for your help.

Input
There are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:
1) An integer K(1<=K<=2000) representing the total number of people;
2) K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
3) (K-1) integer numbers(0s<=Di<=50s) representing the time needed for two adjacent people to buy two tickets together.
Output
For every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started his work at 08:00:00 am. The format of time is HH:MM:SS am|pm.
Sample Input

2
2
20 25
40
1
8

Sample Output

08:00:40 am
08:00:08 am

这道题大意如下:K个人窗口排队买票,票可以一张一张卖,也可以挨着的两个人连在一起卖。现在给定卖给每个人一张票的时间,和同时卖给相邻两人票的时间。求卖票所用时间最短是多少。

解题思路

这道题一看到,我就联想到了最长上升子序列。我们只要维护状态矩阵dp,dp[i]代表,当第i个人是最后一个人的时候,卖票所用时间的最短值。第i个人有两种买票的方式,自己单独买,和前一个人一块儿买。那么dp[i]就可以由dp[i-1]和dp[i-2]两个状态转移而来。状态转移公式如下
d p [ i ] = m a x ( d p [ i − 1 ] + S [ i ] , d p [ i − 2 ] + D [ i − 1 ] ) dp[i] = max(dp[i-1]+S[i],dp[i-2]+D[i-1]) dp[i]=max(dp[i1]+S[i],dp[i2]+D[i1])
其中S[i]是第i个人单独卖票所用的钱,D[i-1]代表第i-1和第i个人一起买票所用时间

AC代码

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
//	cout<<78%60;
//        int max_time = 15200;
//		int time_s = max_time%60;
//		int time_m = (max_time/60)%60;
//		int time_h = (max_time/60)/60;
//		cout<<time_s<<endl<<time_m<<endl<<time_h;int N,K;int i,j;int S[2005],D[2005];//int dps[2005],dpm[2005];int dp[2005];cin>>N;while(N--){cin>>K;for(i = 0;i<K;i++) cin>>S[i];for(i = 0;i<K-1;i++) cin>>D[i];if(K==1){int min_time = S[0];int time_s = min_time%60;int time_m = (min_time/60)%60;int time_h = (min_time/60)/60;if(time_h<=4) printf("%02d:%02d:%02d am\n",time_h+8,time_m,time_s);elseprintf("%02d:%02d:%02d pm\n",time_h+8,time_m,time_s);continue;}
//		dps[0] = S[0];
//		dps[1] = S[0]+S[1];
//		dpm[1] = D[0];dp[0] = S[0];dp[1] = min(S[0]+S[1],D[0]);for(i = 2;i<K;i++){dp[i] = min(dp[i-1]+S[i],dp[i-2]+D[i-1]);
//            dpm[i] = dps[i-1]-S[i-1]+D[i-1];
//            dps[i] = min(dps[i-1],dpm[i-1])+S[i];}
//		int min_time = min(dpm[K-1],dps[K-1]);int min_time = dp[K-1];int time_s = min_time%60;int time_m = (min_time/60)%60;int time_h = (min_time/60)/60;if(time_h<=4) printf("%02d:%02d:%02d am\n",time_h+8,time_m,time_s);elseprintf("%02d:%02d:%02d pm\n",time_h+8,time_m,time_s);//		cout<<time_s<<endl<<time_m<<endl<<time_h<<endl;}
}

http://www.ppmy.cn/news/126025.html

相关文章

[kuangbin带你飞]专题十二 基础DP1

ID Origin Title 题解连接 167 / 465 Problem A HDU 1024 Max Sum Plus Plus here 234 / 372 Problem B HDU 1029 Ignatius and the Princess IV 水题&#xff01;&#xff01;&#xff01; 161 / 259 Problem C HDU 1069 Monkey and Banana here …

R1286K010E(DP1/107)

R1286K010E,电源IC R1286K010E(DP1/107) 2ch DCDC(Step Up DC/DC and lnverting DC/DC) 2ch DCIDC转换器是专为AMOL ED显示电源而设计的。它包括 升压式直流变换器和逆变式DC/DC变换器。 输出电压&#xff1a;【4.6V到5.8V可调音圈】 操作电压&#xff1a;【2.3V至5.5V】 输出电…

遭遇krnln.fnr,com.run,shell.fne,dp1.fne,eAPI.fne,internet.fne,RegEx.fnr,spec.fne等

遭遇krnln.fnr,com.run,shell.fne,dp1.fne,eAPI.fne,internet.fne,RegEx.fnr,spec.fne等 一位网友说他的电脑可能中病毒了&#xff0c;症状为把U盘中的文件夹改名后再双击&#xff0c;就提示找不到文件夹。 通过&#xff31;&#xff31;远程协助&#xff0c;先检查U盘&#xf…

极客日报第 71 期:虎牙被抬员工当事人再发声;Android 12 DP1 带来新隐私功能;IBM 考虑出售 Watson Health 业务

文章目录 一、互联网快讯二、程序员专属三、Github 每日精选四、CSDN 社区优质博文精选 一、互联网快讯 1、茄子快传发现多个安全漏洞 安全公司趋势科技报告在茄子快传中发现多个安全漏洞&#xff0c;而它的漏洞能导致远程代码执行。茄子快传是下载量最高的传输应用&#xff…

Zut_round 8(多维dp1)

A: 这一题我开始的想法是&#xff1a;先找出两个字符串的最长公共子序列的长度&#xff0c;在用两个字符串中的较大值减它。但交了好几次一直wa&#xff0c;就换了一种思路 #include <bits/stdc.h> using namespace std; const int N 1005; char a[N],b[N]; int f[N][N…

RCE漏洞演示,墨者靶场

#案列演示 打开墨者靶场&#xff0c;黑盒#命令注入执行分析 这个功能点有这么个功能&#xff0c;进行类似的像我们电脑上ping命令&#xff0c;这相当于就满足了命令&#xff0c;明显可能出现命令执行漏洞&#xff0c;可控变量和漏洞函数都存在。第一要去分析是什么操作系统&am…

DP1:数塔

// // main.cpp // dp1 // // Created by 布拉yuan on 2017/9/16. // Copyright © 2017年 Zan. All rights reserved. // #include <iostream> using namespace std; int a[110][110]; int dp[110][110]; int max(int a, int b){ return a > b ? …

C++编程计算平均数、众数和中位数,可以快速解决计算问题

说明 求N个整数的平均数&#xff0c;众数和中位数。 小知识&#xff1a; 众数 如有9个数&#xff1a;17 13 17 9 17 17 3 16 17  17出现的次数最多&#xff0c;即为这组数的众数。 此题保证众数是唯一的。中位数 如有9个数&#xff1a;102 170 96 90 97 106 110 182 100  将…