zoukankan      html  css  js  c++  java
  • UVA 1025 A Spy in the Metro

    A Spy in the Metro

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    
    int INF=0x3f3f3f3f;
    int kase=0;
    
    int main()
    {
        int n;
        while(scanf("%d",&n)&&n!=0)
        {
            int T,M1,M2,time[n+1];
            scanf("%d",&T);
            int dp[T+1][n+1];
    
            int has_train[T+100][n+1][2];
    
            memset(has_train,0,sizeof(has_train));
            memset(time,0,sizeof(time));
            memset(dp,0,sizeof(dp));
    
            for(int i=1; i<n; i++)
                scanf("%d",&time[i]);
    
            scanf("%d",&M1);
            for(int i=0; i<M1; i++)
            {
                int a;
                scanf("%d",&a);
                int k=a;
                for(int j=1; j<=n; j++)
                {
                    has_train[k][j][0]=1;
                    k+=time[j];
                }
    
            }
    
            scanf("%d",&M2);
            for(int i=0; i<M2; i++)
            {
                int a;
                scanf("%d",&a);
                int k=a;
                for(int j=n; j>=1; j--)
                {
                    has_train[k][j][1]=1;
                    k+=time[j-1];
                }
    
            }
    
            for(int i=1; i<=n-1; i++) dp[T][i]=INF;
            dp[T][n]=0;
    
            for(int i=T-1; i>=0; i--)
                for(int j=1; j<=n; j++)
                {
                    dp[i][j]=dp[i+1][j]+1;
                    if(j<n&&has_train[i][j][0]&&i+time[j]<=T)
                        dp[i][j]=min(dp[i][j],dp[i+time[j]][j+1]);
                    if(j>1&&has_train[i][j][1]&&i+time[j-1]<=T)
                        dp[i][j]=min(dp[i][j],dp[i+time[j-1]][j-1]);
    
                }
    
            cout<<"Case Number "<<++kase<<": ";
            if(dp[0][1]>=INF) cout<<"impossible
    ";
            else cout<<dp[0][1]<<"
    ";
        }
        return 0;
    }
    

      

  • 相关阅读:
    Grove.net实践ORM学习笔记
    COM+的事务
    Delphi中MIDAS线程模型
    Delphi中封装ADO之我重学习记录。。。
    100 多个JaveScript 常用函数
    javascript 事件
    js 收藏
    js 常用函数
    表单11种Input的高级用法
    UltraEdit 使用技巧
  • 原文地址:https://www.cnblogs.com/zhangliu/p/7057751.html
Copyright © 2011-2022 走看看