题目链接

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. 调整type="file"时的input的

    <input type="file"> 在ie下的视图如下 而在firefox下的是 一般为了界面美化的效果,会将其设置为透明,然后覆盖一个<a href = & ...

  2. dedecms中的模版不解析dede:global

    先安装dedecms,配置好各项内容,栏目,网站内容等. 最近在使用dedecms做后台开发一个手机网站的项目,前端设计都是用html5来设计.很多地方都需要使用dede:global标签来调取全局变 ...

  3. 时间迭代和BigDecimal操作

    常规小操作的代码: import java.math.BigDecimal; import java.sql.Timestamp; import java.text.SimpleDateFormat; ...

  4. TensorFlow笔记一 :测试和TFboard使用

    一 .第一个TF python3.6 import tensorflow as tf x=2 y=3 node1=tf.add(x,y,name='node1') node2=tf.multiply ...

  5. windows下用vscode写C++

    [本文参考:https://www.cnblogs.com/zhuzhenwei918/p/9057289.html  和 https://www.zhihu.com/question/3031589 ...

  6. 【React Native开发】React Native控件之DrawerLayoutAndroid抽屉导航切换组件解说(13)

    ),请不要反复加群! 欢迎各位大牛,React Native技术爱好者增加交流!同一时候博客左側欢迎微信扫描关注订阅号,移动技术干货,精彩文章技术推送! 该DrawerLayoutAndroid组件封 ...

  7. VS2010编译OpenSSL(两个版本)

    第一个版本: 编译工具 VS2010 OpenSSL版本 openssl-1.0.0a 下载 OpenSSL http://www.openssl.org/ 下载 from http://www.ac ...

  8. Npm 被公司墙解决方法

    npm被公司墙了,不能用npm安装任何包应用了. npm ERR! Darwin npm ERR! argv "/usr/local/Cellar/node/6.4.0/bin/node&q ...

  9. [jjzhu学java]之solr4.9同步mysql数据

    Solr是一个高性能,採用Java5开发,基于Lucene的全文搜索server.同一时候对其进行了扩展,提供了比Lucene更为丰富的查询语言,同一时候实现了可配置.可扩展并对查询性能进行了优化,而 ...

  10. centos 6.9 x86 安装搭建hadoop集群环境

    又来折腾hadoop了 文件准备: centos 6.9 x86 minimal版本 163的源 下软件的时候可能会用到 jdk-8u144-linux-i586.tar.gz ftp工具 putty ...