pku 1887 Testing the CATCHER(DP)

 

world finial 中的水题,简单DP

#include <iostream> using namespace std; #define Max(x,y) (x>y?x:y) short height[10005]; short count[10005];//count[n]表示以把height[n]的导弹作为最后拦截的导弹时,最大的拦截导弹数量 int n,k; int main() { k=0; while(++k) { scanf("%d",&height[0]);//读入高度 if(height[0]==-1) break; n=1; while(scanf("%d",&height[n])&&height[n]!=-1) { n++; } count[0]=1; height[n]=-1;//在末端虚构一个高度为-1的导弹 for(int i=1;i<=n;i++) { count[i]=1; for(int j=i-1;j>=(count[i]-1);j--)//DP { if(height[i]<height[j]) { count[i]=Max(count[i],count[j]+1); } } } printf("Test #%d:/n maximum possible interceptions: %d/n/n",k,count[n]-1);//输出结果,注意剪掉那个虚构的导弹 } return 0; }  

 

你可能感兴趣的:(pku 1887 Testing the CATCHER(DP))