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 ...
随机推荐
- ubuntu下C/C++编程起步
1. 安装VMware虚拟机软件 2. 在VMware中安装linux系统,这里安装的是Ubuntu.(用 VMware 安装 Ubuntu 12.04详细过程图解) 3. ubuntu有自带文本编辑 ...
- 转: 三大WEB服务器对比分析(apache ,lighttpd,nginx) (2008年的旧文,仅供参考之用)
from: http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html 三大WEB服务器对比分析(apache ,lighttp ...
- mysql 升序 字段值为NULL 排在后面
select * from yryz_products_t order by isnull(sort),sort;
- Notification(二)——PendingIntent的flag导致数据同样的问题
MainActivity例如以下: package cc.cu; import android.os.Bundle; import android.view.View; import android. ...
- linux过滤ip段
https://www.2cto.com/net/201307/227257.html
- mongodb springdata 问题处理
发现spring4-mongo3.2.1 加上用户名密码认证后无法认证的问题. 1.必须在当前使用的数据库下建用户,权限可以给readWrite 2.由于mongodb2和mongodb3的用户认证方 ...
- centOS中修改语言环境
在终端中打开 键入 vim ~/.bashrc 在最后一行键入 export LANG="zh_CH.UTF-8"
- CocoaPods Podfile详解与使用
1.为什么需要CocoaPods 在进行iOS开发的时候,总免不了使用第三方的开源库,比如SBJson.AFNetworking.Reachability等等.使用这些库的时候通常需要: 下载开源库的 ...
- ANDROID 推送到底哪家强(转)
之前在群里有同学问我关于推送的一些问题,解答之后我觉得这个话题还挺有用,因为几乎大部分人都会遇到这个问题,那姑且就写篇文章总结给你们吧. 1. 为什么要用推送? 推送功能可谓是现如今任何一个 App ...
- 多媒体开发之---h264 取流解码实现
解码器在解码时,首先逐个字节读取NAL的数据,统计NAL的长度,然后再开始解码. nal_unit( NumBytesInNALunit ) { /* NumBytesInNALunit为统计出来的 ...