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
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)的更多相关文章

  1. kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)

    Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7949   Accepted: 42 ...

  2. kuangbin专题十二 POJ1661 Help Jimmy (dp)

    Help Jimmy Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14214   Accepted: 4729 Descr ...

  3. kuangbin专题十二 HDU1176 免费馅饼 (dp)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  5. kuangbin专题十二 HDU1074 Doing Homework (状压dp)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  6. kuangbin专题十二 HDU1069 Monkey and Banana (dp)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  8. kuangbin专题十二 HDU1114 Piggy-Bank (完全背包)

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. kuangbin专题十二 HDU1087 Super Jumping! Jumping! Jumping! (LIS)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

随机推荐

  1. appium运行时启动失败

    1.检查服务是否开启 2.简单Android设备是否连接成功 3.检查4723端口是否被占用: netstat -ano|findstr '4723' 查到被占用后,找到pid,进入任务管理器查看该p ...

  2. 【SymmetricDS】SymmetricDS是如何工作的

    2018-04-20  by 安静的下雪天  http://www.cnblogs.com/quiet-snowy-day/p/8890785.html  本文翻译自SymmetricDS官方文档   ...

  3. windows服务编写和“以管理员运行”程序的方法

    本文将首先解释如何 创建 一个定期查询可用物理内存并将结果写入某个文本文件的服务.然后指导你完成生成,安装和实现服务的整个过程. 第一步:主函数和全局定义 首先,包含所需的头文件.例子要调用 Win3 ...

  4. 计算数组arr中所有元素的和

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. AndroidImageSlider(图片轮播控件)

    1,引入 dependencies { compile "com.android.support:support-v4:+" compile 'com.squareup.picas ...

  6. 如何判断一个字符串是否是UTF8编码

    UTF8是以8bits即1Bytes为编码的最基本单位,当然也可以有基于16bits和32bits的形式,分别称为UTF16和UTF32,但目前用得不多,而UTF8则被广泛应用在文件储存和网络传输中. ...

  7. Nginx 正向代理和反向代理

    正向代理的概念 正向代理,也就是传说中的代理,他的工作原理就像一个跳板,简单的说,我是一个用户,我访问不了某网站,但是我能访问一个代理服务器这个代理服务器呢,他能访问那个我不能访问的网站于是我先连上代 ...

  8. python3-字典中的一些常用方法

    # Auther: Aaron Fan #在dict_dict字典中包含字典那个脚本里介绍了这个方法的用法:'''print(av_catalog.setdefault('大陆',{'www.baid ...

  9. 自动化打包资源混淆集成python实践----打包

    1.自动化打包方案 1)友盟多渠道多渠道打包 2)gradle productFlavors系统的条件编译 3)美团打包 4)APK文件注释写入渠道号 2.各打包方案简介 1)友盟多渠道多渠道打包(w ...

  10. Gym - 100792C Colder-Hotter(三分交互)

    Colder-Hotter Statements This is an interactive problem. Egor and Petr are playing a game called «Co ...