uva 11766 Racing Car Computer(DP)
2014-01-27 22:36
387 查看
F | Racing Car Computer Input: Standard Input Output: Standard Output |
N 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,
a (The number of cars in front of him) & b (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 -
a & 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”, whereX 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 |
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 2010; int dp[maxn][maxn]; int vis[maxn][maxn] = {0}, v , s; struct car{ int p1 , p2; car(int a = 0, int b = 0){ p1 = a , p2 = b; } }C[maxn]; int N; bool cmp(car c1 , car c2){ if(c1.p2 == c2.p2){ return c1.p1<c2.p1; } return c1.p2<c2.p2; } void initial(){ s = 0; } void readcase(){ int f , b , cur = 1; for(int i = 1;i <= N;i++){ scanf("%d%d" , &f , &b); if(f+b >= N) s++; else C[cur++] = car(f+1 , N-b); } sort(C+1 , C+cur , cmp); } int DP(int k ,int i , int sum){ if(k > N-s) return 0; if(vis[k][i] == v) return dp[k][i]; vis[k][i] = v; int tem = 1e9; if(C[i].p1 == C[k].p1 && C[i].p2 == C[k].p2 && sum < C[i].p2-C[i].p1+1){ dp[k][i] = DP(k+1 , i , sum+1); return dp[k][i]; } if(C[i].p2 < C[k].p1){ tem = min(DP(k+1 , i , sum)+1 , DP(k+1 , k , 1)); }else{ tem = min(tem , DP(k+1 , i , sum)+1); } return dp[k][i] = tem; } int main(){ int c = 1; v = 1; while(cin >> N && N){ initial(); readcase(); printf("Case %d: %d\n" , c++ , s+DP(1 ,0 , 1)); v++; } return 0; }
相关文章推荐
- Codeforces Round #226 (Div. 2) <A-C E>
- Linux学习笔记 - ARP与RARP
- OCP-1Z0-053-200题-33题-612
- poj 3286 How many 0's? --- 数位dp
- 线程的状态
- C语言模拟MATRIX特效
- OCP-1Z0-053-V13.02-612题
- 深入理解计算系统读书笔记(一)
- Spring MVC 3.1多视图协商配置(json、xml、freemarker)
- log4j 和slf4j的比较
- POJ 3261 Milk Patterns(后缀数组)
- 黑马程序员__java基础9 包 线程1
- ORA-01795的原因及解决办法
- kettle 源码分析
- sccm安装客户端代理软件
- Linux学习笔记 - Gateway / Router
- STL泛型编程学习之String系列容器
- 关于续行符
- CMUSphinx Wiki--Open Source Toolkit For Speech Recognition
- 新版微信全体验――微信5.2 for iPhone (高富帅尊享版)