HDU - 1260 Tickets 【DP】
题目链接
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】的更多相关文章
- hdoj 1260 Tickets【dp】
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- hdu 2845——Beans——————【dp】
Beans Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets
2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...
- 【DP】HDU 1260
HDU 1260 Tickets 题意:有N个人要买票,你可以一个一个人卖票,时间分别为Xs,也可以相邻两个人一起卖票,时间为Ys,从早上八点开始卖票,问你何时最早将N个人的票卖完. 思路:解决情况是 ...
- HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】
HDOJ_1087_Super Jumping! Jumping! Jumping! [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- Kattis - honey【DP】
Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...
- HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】
HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...
- HDOJ 1501 Zipper 【DP】【DFS+剪枝】
HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDOJ 1257 最少拦截系统 【DP】
HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- 【spring boot logback】日志logback格式解析
日志logback格式解析 logback官网 格式解析 https://logback.qos.ch/manual/layouts.html#ClassicPatternLayout 官网格式解析有 ...
- VS2010中打开VS2012项目的方法
VS2012中对C#的支持度非常好,不管是编写方便程度(不需要插件就能高亮代码及代码自动提示功能),还对MFC的一些功能优化很多. 修改两个工程文件就把VS2012的项目移植到VS2010中去的方法如 ...
- java编程思想第四版第9章
练习3: public class MainTest { public static void main(String args[]){ Bcycle b=new Bcycle(); b.print( ...
- haifeng
[root@localhost 桌面]# yum list|grep wubi ibus-table-chinese-wubi-haifeng.noarch -.el7 base ibus-table ...
- PocketBeagle 初高级设置
前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正.本文使用markdown标记语言写成,为获得最好的阅读体验,请访问我的博客原文. 1. PocketBeagle Summary ...
- Odoo11 新功能 : 栏位隐藏
Odoo11增加了一个 新的 modifier-. 先上 前端框架代码 invisible / readonly / required 这几个 是经常在用的, column_invis ...
- Shell脚本之:while
while循环用于不断执行一系列命令,也用于从输入文件中读取数据:命令通常为测试条件.其格式为: while command do Statement(s) to be executed if com ...
- cocos2dx3.x使用cocostudio触摸事件不响应的奇葩问题
刚刚使用3.1,发现了一些关于触摸的不同之处,对于习惯于2.x的人还是认为坑啊,简单总结一下: 使用cocostudio加进来的ui,当某个可触但不可见的时候,给他加入不论什么触摸监听事件都是依照不可 ...
- Effective C++ 35,36,37
35.使公有继承体现 "是一个" 的含义. 共同拥有继承意味着 "是一个".如 class B:public A. 说明类型B的每个对象都是一个类型A的对象, ...
- Leetcode Array 16 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...