kuangbin专题十二 HDU1260 Tickets (dp)
Tickets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8077 Accepted Submission(s): 4101
Problem Description
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.
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.
Input
There are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:
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.
Output
For every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started his work at 08:00:00 am. The format of time is HH:MM:SS am|pm.
Sample Input
2
20 25
40
1
8
Sample Output
08:00:40 am
08:00:08 am
题目大意:给出n个人,n个数表示每人单买的价格,n-1个数,表示相邻的两个人合买的价格。
思路:画了画,感觉挺难的。然后深搜写了,感觉得记忆化,然后发现可以用dp[pos], 表示到达该点之前的所有和的最小值。(具体见注释)
dp递推的状态方程没有写出来。
dp[i] = minn(dp[i-1] + a[i], dp[i-2] + b[i-1]) // 单人,双人
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-;
const ll mod = 1e9+;
//head
int n, a[], b[], minn, dp[];
void dfs(int pos, int sum) {
if(pos >= n) {//如果pos >= n
if(sum < minn)
minn = sum;//更新minn
return;
}
if(sum >= dp[pos]) //如果达到pos的sum 比之前到达的还大,没有必要再搜索了
return;
dp[pos] = sum;//更新dp[pos]
dfs(pos+, sum + a[pos]);
dfs(pos+, sum + b[pos]);
} int main() {
int t;
while(~scanf("%d", &t)) {
while(t--) {
scanf("%d", &n);
minn = inf;
for(int i = ; i < n; i++)
scanf("%d", &a[i]);
for(int i = ; i < n-; i++)
scanf("%d", &b[i]);
b[n-] = a[n-];//手动添加一个
fill(dp, dp + n, inf);//初始化inf
dfs(, );//dfs(pos, sum)
int h, m, s;//时间处理
h = minn / ;
m = (minn - h * ) / ;
s = minn % ;
printf("%02d:%02d:%02d ", + h, m, s);
if(h < )
printf("am\n");
else if(h == && (m + s) == )
printf("am\n");
else
printf("pm\n");
}
}
}
kuangbin专题十二 HDU1260 Tickets (dp)的更多相关文章
- kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)
Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7949 Accepted: 42 ...
- kuangbin专题十二 POJ1661 Help Jimmy (dp)
Help Jimmy Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14214 Accepted: 4729 Descr ...
- kuangbin专题十二 HDU1176 免费馅饼 (dp)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- kuangbin专题十二 HDU1074 Doing Homework (状压dp)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- kuangbin专题十二 HDU1069 Monkey and Banana (dp)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- kuangbin专题十二 HDU1114 Piggy-Bank (完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- kuangbin专题十二 HDU1087 Super Jumping! Jumping! Jumping! (LIS)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
随机推荐
- Python No module named pkg_resources
好记性不如烂笔头. I encountered the same ImportError today while trying to use pip. Somehow the setuptools p ...
- C语言学习笔记--#和##操作符
1. #运算符 (1)#运算符用于在预处理期将宏的参数转换为字符串 (2)#的转换作用是在预处理期完成的,因此只在宏定义中有效,即其他地方不能用#运算符 (3)用法:#define STRING(x) ...
- ios下编译opencv
如果想要在ios下编译opencv 需要安装Cmake 这里通过homebrew 来安装cmake ios下打开终端然后先安装 homebrew :(mac 下自带ruby) ruby -e &quo ...
- 猪羊——HTML解析
HTML标签和属性大全见:http://www.cnblogs.com/Mr-liyang/p/5797976.html CSS样式大全:http://www.cnblogs.com/Mr-liyan ...
- hBase-thrift 实践(java)
参考官网: http://wiki.apache.org/hadoop/Hbase/ThriftApi 环境:hbase-0.98.1-cdh5.1.0,hadoop-2.3.0-cdh5.1.0,c ...
- java中是如何解决编码问题的,比如char类型的对象是如何存储的呢?
主题句:每个编码形式将字符从字符集转换为编码数据. 说白了一个代码点就是一个Unicode字符.代码单元就是代码点的集合. 字符视图 要了解字符集标准,您必须能区分三种不同的字符视图: 字符集(字符的 ...
- p4570 [BJWC2011]元素
传送门 分析 对法力值从大到小排序然后对编号跑线性基即可 代码 #include<iostream> #include<cstdio> #include<cstring& ...
- SDUT 2129 树结构练习——判断给定森林中有多少棵树
树结构练习——判断给定森林中有多少棵树 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 众 ...
- mingw和libcurl
想用curl来做rest的客户端.所以就研究下这方面东西. 1:安装mingw 为什么用mingw,小巧,必vs快,gcc了解的多一些, http://tdm-gcc.tdragon.net/down ...
- java全栈day09----继承 抽象类
01继承的概述 在Java中,类的继承是指在一个现有类的基础上去构建一个新的类, 构建出来的新类被称作子类,现有类被称作父类在java中 继承如何来实用呢?举个例子 继承的定义格式和使用 *A:继承的 ...