记录编号 98010 评测结果 WWWWWWAAWW
题目名称 导弹拦截 最终得分 20
用户昵称 Gravatar超级傲娇的AC酱 是否通过 未通过
代码语言 C++ 运行时间 0.601 s
提交时间 2014-04-21 16:16:24 内存使用 0.32 MiB
显示代码纯文本
  1. /*
  2. Dirworh
  3. */
  4. #include <iostream>
  5. #include <cstdio>
  6. #include <vector>
  7. using namespace std;
  8. struct pos
  9. {
  10. int x,y,z;
  11. };
  12. vector<pos>Pos;
  13. int F1[1002],n,Path[1002];
  14. bool v[1002];
  15. int DP();
  16. void Opt_V();
  17. bool Jud();
  18. void init();
  19.  
  20. int main()
  21. {
  22. freopen("bomba.in","r",stdin);
  23. freopen("bomba.out","w",stdout);
  24. pos P;
  25. int i,j,Ans=0;
  26. cin>>n;
  27. init();for(i=0;i<n;i++)v[i]=false;
  28. for(i=0;i<n;i++)
  29. {
  30. cin>>P.x>>P.y>>P.z;
  31. Pos.push_back(P);
  32. }
  33. cout<<DP()<<endl;
  34. int Len=n,D;
  35. while(!Jud())
  36. {
  37. D=DP();
  38. Opt_V();
  39. Len-=D;
  40. Ans++;
  41. }
  42. cout<<Ans;
  43. return 0;
  44. }
  45. bool Jud()
  46. {
  47. bool B=true;
  48. for(int i=0;i<n;i++)
  49. B=B&v[i];
  50. return B;
  51. }
  52. int DP()
  53. {
  54. int i,j,loc=0,Max=0;
  55. for(i=1;i<n;i++)
  56. {
  57. if(!v[i])
  58. for(j=0;j<i;j++)
  59. if(Pos[i].x>Pos[j].x&&Pos[i].y>Pos[j].y&&Pos[i].z>Pos[j].z&&!v[j])
  60. {
  61. F1[i]=max(F1[j]+1,F1[i]);
  62. Path[i]=j;
  63. //标记数组v与路径数组p
  64. /*
  65. 将每次路径上的节点进行标记。
  66. 并在v中标记,在DP时加上条件v
  67. 时间复杂度上界为n^3
  68. */
  69. }
  70. }
  71. //return *max_element(F1,F1+n);
  72. for(i=0;i<n;i++)
  73. if(F1[i]>Max&&!v[i])
  74. Max=F1[i],loc=i;
  75. return F1[loc];
  76. }
  77. void Opt_V()
  78. {
  79. int i,loc=0,Max=0;
  80. for(i=0;i<n;i++)
  81. if(F1[i]>Max&&!v[i])
  82. Max=F1[i],loc=i;
  83. while(loc!=-1)//位置指向自身无法处理单元素情形
  84. {
  85. v[loc]=true;
  86. loc=Path[loc];
  87. }
  88. }
  89. void init()
  90. {
  91. for(int i=0;i<=n;i++)F1[i]=1,Path[i]=-1;
  92. }