HDU 1260 Tickets(简单dp)
Tickets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 711 Accepted Submission(s): 354
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.
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.
状态转移方程:
dp[0] = 0;
dp[1] = a[1];
dp[i] = min(dp[i-1] + a[i], dp[i-2] + b[i-1]);(i : 1->k)
解题代码:
1 // File Name: Tickets 1260.cpp
2 // Author: sheng
3 // Created Time: 2013年05月24日 星期五 21时22分20秒
4
5 #include <iostream>
6 #include <stdio.h>
7 #include <string.h>
8 using namespace std;
9
10 const int max_k = 2003;
11
12 int dp[max_k], a[max_k], b[max_k];
13 int min (int a, int b)
14 {
15 return a > b ? b : a;
16 }
17
18 int main ()
19 {
20 int n;
21 int k, MIN;
22 int sec, minute, hour;
23 scanf ("%d", &n);
24 while (n --)
25 {
26 scanf ("%d", &k);
27 for (int i = 1; i <= k; i ++)
28 scanf ("%d", &a[i]);
29 for (int i = 1; i < k; i ++)
30 scanf ("%d", &b[i]);
31 dp[0] = 0;
32 dp[1] = a[1];
33 for (int i = 2; i <= k; i ++)
34 {
35 dp[i] = min(dp[i - 1] + a[i], dp[i - 2] + b[i - 1]);
36 }
37 // printf ("%d\n", dp[k]);
38 minute = dp[k]/60;
39 sec = dp[k]%60;
40 hour = 8 + minute/60;
41 minute %= 60;
42 if (hour > 12)
43 hour -= 12;
44 if (hour < 10)
45 printf ("0");
46 printf ("%d:", hour);
47 if(minute < 10)
48 printf ("0");
49 printf ("%d:", minute);
50 if (sec < 10)
51 printf ("0");
52 printf ("%d", sec);
53 printf (" %s\n", hour <= 12 ? "am" : "pm");
54 }
55 return 0;
56 }
G++
HDU 1260 Tickets(简单dp)的更多相关文章
- HDU - 1260 Tickets 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...
- 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets
2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...
- HDU 1260 Tickets (普通dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1260 Tickets DP
http://acm.hdu.edu.cn/showproblem.php?pid=1260 用dp[i]表示处理到第i个的时候用时最短. 那么每一个新的i,有两个选择,第一个就是自己不和前面的组队, ...
- HDU 1260 Tickets(基础dp)
一开始我对这个题的题意理解有问题,居然超时了,我以为是区间dp,没想到是个水dp,我泪奔了.... #include<stdio.h> #include<string.h> # ...
- 题解报告:hdu 1260 Tickets
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...
- hdu 1260 Tickets
http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...
- POJ 1260 Pearls 简单dp
1.POJ 1260 2.链接:http://poj.org/problem?id=1260 3.总结:不太懂dp,看了题解 http://www.cnblogs.com/lyy289065406/a ...
- hdoj 1260 Tickets【dp】
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
随机推荐
- 菜鸟学习Hibernate——简单的增、删、改、查操作
上篇博客利用Hibernate搭建起一个简单的例子,把数据库的映射显示了出来在上一篇的博客基础上这篇博客讲述如何利用Hinbernate框架实现简单的数据库操作. 1.加入junit.jar 2.新建 ...
- bat完美关机命令
@echo off title OLIVER-COMPUTER mode con cols= lines= color 0d shutdown /a >nul >nul ver > ...
- 使用VMDepot镜像快速部署CKAN开放数据门户
最新发布的CKAN VMDepot镜像针对中国用户强化了中文支持,提升了与MS Office办公软件的互操作性,并集成了常用插件和最佳实践配置参数. 使得CKAN原本十分复杂繁琐的部署流程变得非常简单 ...
- quartz 数据表字典
首次整理,可能有错误,还有少许的未整理,希望看到的人能给点补充(包括指点错误) 表名 表说明 自定义触发器 QRTZ_BLOB_TRIGGERS 列名(英) 列名(中) 数据类型 列长度 是否为空 列 ...
- VBS数组函数学习实例分析
Array 函数 返回包含数组的Variant. Array(arglist) 参数:arglist是赋给包含在Variant中的数组元素的值的列表(用逗号分隔).如果没有指定此参数,则将会创建零长度 ...
- HashCode作用
作用: 1.HashCode的存在主要是为了查找的快捷性,HashCode是用来在散列存储结构中确定镀锡的存储地址的 2.如果两个对象的equals相等,那么HashCode一定相等,反之不行 3.如 ...
- 搭建SpringMVC+MyBatis开发框架四
在src/main下面新建一个resouces文件夹,我们继续配置一些资源 1.新增applicationContext.xml:  <?xml version="1.0" ...
- 在FreeBSD上搭建Mac的文件及time machine备份服务
上周将工作用电脑由公司配备的台式机切换到自己低配的macbook air上面,小本本的128G SSD远远不能满足工作的储存需要,但又不舍得入手昂贵的AirPort Time Capsule,于是考虑 ...
- 安装配置OPENCMS的Replication cluster(从)详细过程
1. 把opencms.war拷贝到tomcat下的webapps目录,启动tomcat服务. 2. 在安装之前,打开解压缩后的war包目录(tomcat启动后会自动把war包解开),删除目录 $ ...
- DiskFileItemFactory类---分析及运用
DiskFileItemFactory类 将请求消息实体中的每一个项目封装成单独的DiskFileItem (FileItem接口的实现) 对象的任务由 org.apache.commons.file ...