zoukankan      html  css  js  c++  java
  • hdu1257 最少拦截系统 ——DP么?

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257

    题目大意:

      中文的……

    题目思路:

      人家说是DP,求最长不升子序列的个数。好吧……我不是那么做的。

      我的思路是,从前往后扫一遍,访问过的标记为true,记录一下个数就OK了。

     1 #include <iostream>
     2 #include <cstdlib>
     3 #include <cstdio>
     4 #include <cstring>
     5 using namespace std;
     6 int b[1000];
     7 bool a[1000];
     8 int main(void) {
     9   int n;
    10 #ifndef ONLINE_JUDGE
    11   freopen("1257.in", "r", stdin);
    12 #endif
    13   while (~scanf("%d", &n)) {
    14     int i, j, cnt = 0;
    15     for (i = 0; i < n; ++i) scanf("%d", b+i);
    16     memset(a, false, sizeof(a));
    17     for (i = 0; i < n; ++i) {
    18       while (a[i]) ++i;
    19       if (i == n) break;
    20       if (!a[i]) cnt++; a[i] = true; j = i;
    21       int tmp = b[j];
    22       while (j < n-1) {
    23         if (!a[j+1] && b[j+1] <= tmp) {a[j+1] = true; tmp = b[j+1];}
    24         ++j;
    25       }
    26       int k;
    27       for (k = 0; k < n; ++k) if (!a[k]) break;
    28       if (k == n) break;
    29     }
    30     printf("%d\n", cnt);
    31   }
    32   return 0 ;
    33 }

    写的时候还是出现了错误,最后还是发现了,幸亏自己出了一组数据,^_^

  • 相关阅读:
    C#按模板生成word文档总结
    Aspose.Words.dll根据模板生成word
    WCF服务
    Fiddler抓包工具
    文本过长显示...
    java JDK 环境变量配置
    js return关键字
    js限制文本框输入内容
    jQuery学习一
    JSON 教程
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/3112739.html
Copyright © 2011-2022 走看看