Tickets

H - Tickets

参考:Tickets——H

思路:对于每一个买票的人来说,只需要决定他是自己买票还是跟前面的人一块买票即可。

假设三个人 A B C,当 C 要跟 B 一块买票的时候,B 不能够跟 A 一起买。

那么状态方程就应该是dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]),保证了不会有一个人跟两个人一块买票的情况。

想清楚什么变什么不变。

代码:

// Created by CAD on 2019/10/26.
#include <bits/stdc++.h>
using namespace std;

int dp[2005],a[2005],b[2005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;  cin>>t;
    while(t--)
    {
        int k;  cin>>k;
        for(int i=1;i<=k;++i)
            cin>>a[i];
        for(int i=2;i<=k;++i)
            cin>>b[i];
        dp[1]=a[1];
        for(int i=2;i<=k;++i)
            dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]);
        int s=dp[k];
        int m=s/60; s%=60;
        int h=m/60; m%=60;
        cout<<setw(2)<<setfill('0')<<8+h<<":"<<setw(2)<<m<<":"<<setw(2)<<s<<" "<<((h+8>12)?"pm":"am")<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/CADCADCAD/p/11745167.html

时间: 2024-10-30 05:52:42

Tickets的相关文章

【SGU 390】Tickets (数位DP)

Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell tickets to the passengers. So no wonder that once upon a time in a faraway galaxy one conductor decided to diversify this occupation. Now this conductor

[2016-03-27][HDU][1260][Tickets]

时间:2016-03-27 22:37:37 星期日 题目编号:[2016-03-27][HDU][1260][Tickets] 遇到的问题:分钟数字,除以60以后还要模60 t / 60 % 60 #include <cstdio> #include <algorithm> using namespace std; typedef long long LL; const int maxk = 2000 + 10; int s[maxk],d[maxk]; int dp[maxk]

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first half of digits and the last half of digits. If these two sums ar

POJ 2828 Buy Tickets(线段树--单点更新)

Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 16196   Accepted: 8059 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue- The Lunar New Year wa

poj 2828 Buy Tickets 【线段树点更新】

题目:poj 2828 Buy Tickets 题意:有n个人排队,每个人有一个价值和要插的位置,然后当要插的位置上有人时所有的人向后移动一位当这个插入到这儿,如果没有直接插进去. 分析:分析发现直接插入移动的话花时间太多,我们可不可以用逆向思维.从后往前来,因为最后一个位置是肯定能确定的,而其他的则插入空的第某个位置. 比如第一组样例: 4 0 77 1 51 1 33 2 69 开始时候位置都为空 编号0 1 2 3 首先从最后一个来2 69 第二个位置空,则可以直接放 然后编号变为0 1

POJ 2828 Buy Tickets(线段树)

Language: Default Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 13847   Accepted: 6926 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue- The

Poj2828Buy Tickets线段树

倒着搞就可以了,先进会被后面覆盖. #include <cstdio> #include <cstring> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #include <list> #include <set&g

poj 2828 Buy Tickets

Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 13277   Accepted: 6595 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue- The Lunar New Year wa

POJ训练计划2828_Buy Tickets(线段树/单点更新)

解题报告 题意: 插队完的顺序. 思路: 倒着处理数据,第i个人占据第j=pos[i]+1个的空位. 线段树维护区间空位信息. #include <iostream> #include <cstdio> #include <cstring> using namespace std; struct node { int x,v; } num[201000]; int sum[1000000],ans[201000]; void cbtree(int rt,int l,in

[ACM] hdu 1260 Tickets (动态规划)

Tickets Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 2 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Jesus, what a great movie! Thou