• Racing Car Computer dp


    Racing Car Computer

    Input: Standard Input

    Output: Standard Output

     

    The racing cars of today are equipped with so many sophisticated equipment. Introduction of a new visual transducer which is interfaced with the on-board computer can tell you on the fly how many cars are ahead of you while how many are trailing. There are cars on a racing track. Each has an on-board computer with the new feature. During the race, every single car's computer keeps displaying two integers, (The number of cars in front of him) & (The number of cars behind him) for a particular moment. It is possible that at some time, some of the cars are racing side by side i.e. they are exactly at the same location. A car will not consider any other car at the same location to be a leading or trailing car.

    Now, it is suspected that some of the new transducers are not working properly inside such high speed vehicles. The report with all computers' data generated at a particular timestamp is reported to you. You are to determine the minimum number of cars that  have faulty data.

    Input

    Each test case begins with an integer N (1<=N<=1000), the number of cars on a track. The next N lines each has two integers - b (0<=a,b<=1500) for a particular car.

    The last test case is followed by a line with a single 0 indicating the end of input.

                                                                                                                                                             

    Output

    For each test case, print a line in the format, “Case X: Y”, where X is the case number & Y is the minimum number of cars that must have faulty data according to the report.

    Sample Input                               Output for Sample Input

    4

    2 2

    0 0

    0 2

    3 1

    1

    1 1

    0

    Case 1: 3

    Case 2: 1

      

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <stdio.h>
     4 #include <string.h>
     5 using namespace std;
     6 int ww[1200][1200];
     7 int main()
     8 {
     9     int t,n,i,j,x,y,dp[1200];
    10     t=1;
    11     while(scanf("%d",&n),n)
    12     {
    13         memset(ww,0,sizeof(ww));
    14         memset(dp,0,sizeof(dp));
    15         for(i=0; i<n; i++)
    16         {
    17             scanf("%d%d",&x,&y);
    18             if(x+y>=n)continue;
    19             if(ww[x+1][n-y]==n-y-x)continue;
    20             ww[x+1][n-y]++;
    21         }
    22         for(i=1; i<=n; i++)
    23             for(j=0; j<i; j++)
    24                 dp[i]=max(dp[i],dp[j]+ww[j+1][i]);
    25        printf("Case %d: %d
    ",t++,n-dp[n]);
    26     }
    27 }
    View Code
  • 相关阅读:
    Java 常用工具类
    Shiro 分析
    Oracle 恢复表操作内容
    Struts2 中的配置文件 package name 、namespace 以及 对象方法调用
    MySql 修改字符集
    命名空间、静态函数、实例函数
    Eclipse Tomcate 热部署
    Java Json
    Mybatis 存储过程调用
    HDFS源码分析心跳汇报之数据结构初始化
  • 原文地址:https://www.cnblogs.com/ERKE/p/3646955.html
Copyright © 2020-2023  润新知