博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kuangbin专题十二 HDU1260 Tickets (dp)
阅读量:6256 次
发布时间:2019-06-22

本文共 3278 字,大约阅读时间需要 10 分钟。

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])  // 单人,双人

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 #define mem(a,b) memset((a),(b),sizeof(a))16 #define mp make_pair17 #define pb push_back18 #define fi first19 #define se second20 #define sz(x) (int)x.size()21 #define all(x) x.begin(),x.end()22 typedef long long ll;23 const int inf = 0x3f3f3f3f;24 const ll INF =0x3f3f3f3f3f3f3f3f;25 const double pi = acos(-1.0);26 const double eps = 1e-5;27 const ll mod = 1e9+7;28 //head29 int n, a[2010], b[2010], minn, dp[2010];30 void dfs(int pos, int sum) {31 if(pos >= n) { //如果pos >= n 32 if(sum < minn)33 minn = sum;//更新minn 34 return;35 }36 if(sum >= dp[pos]) //如果达到pos的sum 比之前到达的还大,没有必要再搜索了 37 return;38 dp[pos] = sum;//更新dp[pos] 39 dfs(pos+1, sum + a[pos]);40 dfs(pos+2, sum + b[pos]);41 }42 43 int main() {44 int t;45 while(~scanf("%d", &t)) {46 while(t--) {47 scanf("%d", &n);48 minn = inf;49 for(int i = 0; i < n; i++)50 scanf("%d", &a[i]);51 for(int i = 0; i < n-1; i++)52 scanf("%d", &b[i]);53 b[n-1] = a[n-1];//手动添加一个 54 fill(dp, dp + n, inf);//初始化inf 55 dfs(0, 0);//dfs(pos, sum) 56 int h, m, s;//时间处理 57 h = minn / 3600;58 m = (minn - h * 3600) / 60;59 s = minn % 60;60 printf("%02d:%02d:%02d ", 8 + h, m, s);61 if(h < 12)62 printf("am\n");63 else if(h == 12 && (m + s) == 0)64 printf("am\n");65 else66 printf("pm\n");67 }68 }69 }

 

 

转载于:https://www.cnblogs.com/ACMerszl/p/9572928.html

你可能感兴趣的文章
自动精简配置&重复数据删除核心技术点及其经济效应探究
查看>>
cncert网络安全周报35期 境内被植入后门的政府网站112个 环比上涨24.4%
查看>>
物联网到底是不是泡沫,且看英特尔交出的答案
查看>>
IPv6太落后了:中国加速服务器援建
查看>>
物理引擎中velocity的单位是个什么鬼?
查看>>
oracle的drop命令
查看>>
设计与梳理企业二级流程的路线方法
查看>>
垃圾回收概念与算法
查看>>
TFS实现需求工作项自动级联保存
查看>>
springmvc 4.x 处理json 数据时中文乱码
查看>>
Python练习(day7)
查看>>
网络工程师笔试题总结
查看>>
飞舞的蝴蝶
查看>>
对Map按key和value分别排序
查看>>
Async Performance: Understanding the Costs of Async and Await
查看>>
POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)
查看>>
Linux中select poll和epoll的区别
查看>>
Cocos2d-x之MenuItem
查看>>
远程共享文件夹
查看>>
[转] C/C++中printf和C++中cout的输出格式
查看>>