POJ 1887 Testing the CATCHER

来源:互联网 发布:jsp与php运行环境区别 编辑:程序博客网 时间:2024/06/10 20:13

最长递减序列问题.

#include <cstdio>#include <algorithm>#include <memory.h>using namespace std;const int MAX = 5000;int dp[MAX], g[MAX], A[MAX];int main(int argc, char const *argv[]){int h, caseno = 1;while(scanf("%d", &h) && h != -1){if(caseno != 1){printf("\n");}int idx = 0, ans = 0;do{A[idx++] = h;}while(scanf("%d", &h) && h != -1);reverse(A, A + idx);memset(g, 0x20, sizeof(g));for(int i = 0; i < idx; ++i){int k = lower_bound(g + 1, g + idx + 1, A[i]) - g;dp[i] = k;g[k] = A[i];ans = max(dp[i], ans);}printf("Test #%d:\n  maximum possible interceptions: %d\n", caseno++, ans);}return 0;}


0 0
原创粉丝点击