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 ...
随机推荐
- js防止重复点击
表单元素 disabled 没有之一. el.prop('disabled', true); ajax({}).done(function() { el.prop('disabled', false) ...
- javascript——对象的概念——内建对象
包括内建对象的所有对象都是Object对象的子对象. 1.Array():构建数组的内建构造器函数 例:创建数组方式有两种: 2.Boolean:是对象,与基本数据类型 布尔值 不相同 例:创建Boo ...
- javascript——对象的概念——Object(未完)
http://www.blogjava.net/zkjbeyond/archive/2006/04/16/41336.html javascript中对象只包括属性和方法两种成员.ECMA-262 把 ...
- 使用GSON来生成JSON数据
第二种方法: 当不需要显示某个属性时,在不需要显示出的属性前加transient关键字即可满足 使用gson来解析 使用gson解析 带日期转换 集合类解析:gson中的数组与java中集合类都是对应 ...
- JAVA基础知识总结6(面向对象特征之一:多态)
多 态:函数本身就具备多态性,某一种事物有不同的具体的体现. 体现:父类引用或者接口的引用指向了自己的子类对象. Animal a = new Cat(); 多态的好处:提高了程序的扩展性. 多态的弊 ...
- css水平居中,竖直居中技巧(一)
css水平居中,竖直居中技巧(一)===### 1.效果 ### 2.代码#### 2.1.index.html <!DOCTYPE html> <html lang="z ...
- php 如何禁用eval() 函数实例详解
在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险并经常会出现一些问题,今天我们就一起来看看eval函数对数组的操作及php 如何禁用eval() 函数: <?php $ ...
- 业务逻辑: Quartz的整合应用
1. 请谈一下你对Quartz的理解 思路:根据他解决的什么问题方面去阐述 2. 完成quartz和spring的整合应用 思路:触发时间.任务调度工程 步骤: 1. 创建maven工程,并导入qua ...
- 指静脉屏幕说明usart hmi
1. 1.usart HMI 下载最新版软件 2.如上图可以设置横屏 3.txt的最大字符默认是10 要改大一些 4.t0.txt="aaa" 这是串口通讯命令但前面还有开始码
- 杭电acm 1038题
本题比较简单,但是需要掌握几个小技巧,先上代码 /************************************* 杭电ACM 1038题,已AC ********************* ...