Mountain Road

题意:

n个车,过一条路,有不同的方向,路上不允许同时有两个方向的车,给出每个车的起始时间,方向,和经过路花费的时间,车最小间隔10个时间,求最后一个车通过路的最早的时间。

分析:

dp[i][j][0]表示0方向经过i个车,1方向经过j个车,最后在0方向,最后一个车通过路的最早的时间。dp[i][j][1]表示0方向经过i个车,1方向经过j个车,最后在1方向,最后一个车通过路的最早的时间。注意车间隔。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll  INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod =  1000000007;
struct node{
    int s,t;
}l[210],r[210];
int dp[210][210][2],nl,nr;
void solve(){
    for(int i=0;i<=nl;++i)
        for(int j=0;j<=nr;++j)
        dp[i][j][0]=dp[i][j][1]=INF;
    dp[0][0][0]=dp[0][0][1]=0;
    for(int i=0;i<=nl;++i)
    for(int j=0;j<=nr;++j){
        int ts=dp[i][j][1],te=0;
        for(int k=i+1;k<=nl;++k)
        {
            ts=max(ts,l[k].s);
            te=max(ts+l[k].t,te);
            dp[k][j][0]=min(dp[k][j][0],te);
            ts+=10,te+=10;
        }
        ts=dp[i][j][0],te=0;
        for(int k=j+1;k<=nr;++k)
        {
            ts=max(ts,r[k].s);
            te=max(ts+r[k].t,te);
            dp[i][k][1]=min(dp[i][k][1],te);
            ts+=10,te+=10;
        }
    }
    printf("%d\n",min(dp[nl][nr][0],dp[nl][nr][1]));
}
int main()
{
    char ch[3];
    int ca,m;
    scanf("%d",&ca);
    while(ca--){
        scanf("%d",&m);
        nl=nr=0;
        int a,b;
        while(m--){
            scanf("%s%d%d",ch,&a,&b);
            if(ch[0]==‘A‘){
                    ++nl;
                l[nl].s=a;
                l[nl].t=b;
            }
            else if(ch[0]==‘B‘)
            {
                 ++nr;
                r[nr].s=a;
                r[nr].t=b;
            }
        }
        solve();
    }
return 0;
}
时间: 2024-08-24 13:29:00

Mountain Road的相关文章

dp题目列表

10271 - Chopsticks 10739 - String to Palindrome 10453 - Make Palindrome 10401 - Injured Queen Problem 825 - Walking on the Safe Side 10617 - Again Palindrome 10201 - Adventures in Moving - Part IV 11258 - String Partition 10564 - Paths through the Ho

Soj题目分类

-----------------------------最优化问题------------------------------------- ----------------------常规动态规划  SOJ1162 I-Keyboard  SOJ1685 Chopsticks SOJ1679 Gangsters SOJ2096 Maximum Submatrix  SOJ2111 littleken bg SOJ2142 Cow Exhibition  SOJ2505 The County

gRPC 的route_guide例子

  本文的例子代码在: https://github.com/grpc/grpc-go/tree/master/examples/route_guide 功能就类似目前LBS一样,在每个位置上报一些文字信息, 上报方式有多种.   在 .proto 文件中定义服务 在 .proto 文件中定义一个服务很简单, 就像如下的代码: service RouteGuide { ... } 定义rpc的方法,需要指定他们的 request 和response 类型.gRPC 可以定义四种类型的方法,这个

50-Prepositions

eg:46 with--With her were her son and daughter-in-law; at--We had dinner at a restaurant in Attleborough; from--He appealed for information from anyone who saw the attackers; into--Combine the remaining ingredients and put them into a dish; during--S

poj 3204 Ikki&#39;s Story I - Road Reconstruction

Ikki's Story I - Road Reconstruction 题意:有N个顶点和M条边N, M (N ≤ 500, M ≤ 5,000)  ,试图改变图中的一条边使得从0到N-1的流量增加:问这样的边有几条? 思路:刚最大流入门,之后一看就觉得满流的边就是答案..真是太天真了.之后看了题解,发现满流只是前提(即使满流是几次残量的叠加也是一样),还有一个条件是,该路径的最大流量只受该边影响:即可以从S和T遍历到该边的两个端点,这就是为什么之后还要dfs给点涂色的原因:涂色前要对残余网络

hdoj 1596 find the safest road 【dijkstra】

find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9144    Accepted Submission(s): 3225 Problem Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1

HDU4081 Qin Shi Huang&#39;s National Road System【Kruska】【次小生成树】

Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3979    Accepted Submission(s): 1372 Problem Description During the Warring States Period of ancient China(4

Restoring Road Network

D - Restoring Road Network Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads. The following are

AtCoder Regular Contest 083 D:Restoring Road Network

In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network: People traveled between cities only through roads. It was possible to reach