题目链接

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

题意

有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两个人必须是相邻的

给出 N 个 价格 是 一个一个买的时间花费

给出 N - 1个价格 是 相邻的两个人一起买的时间花费 求出 最小的时间花费

思路

dp[i] 表示 卖到当前这个人的时间花费

状态转移方程

dp[i] = min(dp[i - 2] + b[i - 1], dp[i - 1] + a[i])

当前这个人的时间花费 他 可以单独买 就是 dp[i - 1] + a[i]

也可以 和 上一个人 一起买 就是 dp[i - 2] + b[i - 1] 去最优解

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a, b) memset(a, (b), sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-8; const int INF = 0x3f3f3f3f;
const int maxn = 2e3 + 5;
const int MOD = 1e9 + 7; int a[maxn];
int b[maxn];
int dp[maxn]; int main()
{
int t;
cin >> t;
while (t--)
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i < n; i++)
scanf("%d", &b[i]);
CLR(dp, 0);
dp[0] = 0;
dp[1] = a[1];
for (int i = 2; i <= n; i++)
{
dp[i] = min(dp[i - 2] + b[i - 1], dp[i - 1] + a[i]);
}
int a = 8, b = 0, c = dp[n];
b += c / 60;
c %= 60;
a += b / 60;
b %= 60;
printf("%02d:%02d:%02d am\n", a, b, c);
}
}

HDU - 1260 Tickets 【DP】的更多相关文章

  1. hdoj 1260 Tickets【dp】

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

  2. hdu 2845——Beans——————【dp】

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

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

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

  4. 【DP】HDU 1260

    HDU 1260 Tickets 题意:有N个人要买票,你可以一个一个人卖票,时间分别为Xs,也可以相邻两个人一起卖票,时间为Ys,从早上八点开始卖票,问你何时最早将N个人的票卖完. 思路:解决情况是 ...

  5. HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】

    HDOJ_1087_Super Jumping! Jumping! Jumping! [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  6. Kattis - honey【DP】

    Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...

  7. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  8. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  9. HDOJ 1257 最少拦截系统 【DP】

    HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

随机推荐

  1. 社区管理有捷径!Wish3D Earth社区网格化管理案例重磅上线

    社区网格化是精细化.全覆盖.高效率的社区管理模式,便捷有效的社区网格化管理平台是社区网格化管理的关键. Wish3D Earth全新上线三维社区网格化管理平台,使用实景三维模型作为地图,地形地貌真实展 ...

  2. IOS之怎样把自己开发的App安装到越狱的手机

    场景: 有开发人员账号,能够把设备加到开发人员账号中,真机调试.如今须要打包,安装到的越狱手机上(此越狱手机没有加到开发人员账号中,另外公司的人). 常识: 没有越狱的话,最大的问题就是设备的签名,每 ...

  3. Android开发之布局文件里实现OnClick事件关联处理方法

    一般监听OnClickListener事件,我们都是通过Button button = (Button)findViewById(....); button.setOClickLisener....这 ...

  4. Webpack DLL

    参考自:https://www.jianshu.com/p/a5b3c2284bb6 在用 Webpack 打包的时候,对于一些不经常更新的第三方库,比如 react,lodash,我们希望能和自己的 ...

  5. 国内云引擎平台概览——新浪SAE,阿里ACE,百度BCE

    新浪SAE 平时大家的測试server都是执行在自己的PC上面,用Tomcat或者IIS搭建的本机server. 事实上新浪云平台SinaAppEngine也是挺好用的. 今天总结一下我使用过程中的一 ...

  6. ie下div模拟的表格,表头表体无法对齐

    现象:ie下,如果某个区域滚动显示表格内容(div模拟的table),表体出现滚动条的时候,会跟表头无法对齐. 解决方法:1.首先需要知道两个高度:表体最大高度height1.目前表体要显示的内容高度 ...

  7. VueJS计算属性: computed

    computed属性 HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"&g ...

  8. 笔记本WIFI卡简介

    1.Intel AC9560(CNVI) AC9260(pcie) 3165D2W(pcie) 2.Realtek瑞昱 RTL8822be(pcie) RTL8723BU(USB) 英特尔在300系主 ...

  9. 跟我学AngularJs:Controller数据共享、继承、通信使用具体解释

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主讲了AngularJs中的Controller中数据共享.继承.通信的具体使用 本 ...

  10. php设计模式中的类型安全 指--只接受特定的对象 ---以避免发生错误

    在百度百科中---类型安全代码指访问被授权可以访问的内存位置