zoukankan      html  css  js  c++  java
  • 序列输出ZOJ1108 FatMouse's Speed

    PS:今天上午,非常郁闷,有很多简单基础的问题搞得我有些迷茫,哎,代码几天不写就忘。目前又不当COO,还是得用心记代码哦!

        

        ZOJ1108 FatMouse's Speed 

        

        最长下落子序列,这题挺好的。1Y

        就是在输出序列的上花了很多时间。。

        

        每日一道理
    生命,是一场漫长的棋局。这盘棋没有猎猎西风,没有四起狼烟,只有在取舍和进退中抉择。只有像棋中的小卒那样,勇往直前,毫不退缩沿着沟沟坎坎的人生之路,艰难而执着的求索,前进,才会谱写人生最壮丽的强者之歌。
    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #define MAXN 1001
    using namespace std;
    struct mouse
    {
        int W;
        int S;
        int ID;
        bool operator <(const mouse &tmp) const
        {
                if(W == tmp.W)
                    return S > tmp.S;
                else
                    return W < tmp.W;
        };
    }mice[MAXN];
    struct tt
    {
        int tot;
        int next;
    }f[MAXN];
    int n;
    
    void init()
    {
        int i;
        int w, s;
        n = 0;
        while(~scanf("%d%d",&w,&s))
        {
            mice[n].W = w;
            mice[n].S = s;
            mice[n].ID = n+1;
            n++;
        }
        sort(mice, mice +n);
       /* for(i=0; i<n; ++i)
        {
            printf("%d %d %d\n",mice[i].W, mice[i].S, mice[i].ID);
        }
        */
        for(i=0; i<n; ++i)
        {
            f[i].tot = 0;
            f[i].next = -1;
        }
    }
    void visit(int x)
    {
        printf("%d\n",mice[x].ID);
        if(f[x].next >0)
             visit(f[x].next);
    }
    void dp()
    {
        int i, j, max,k;
        for(i=n-1; i>=0; --i)
        {
            max = 0;k = -1;
            for(j=n-1;j>i; --j)
                if(mice[i].S > mice[j].S && mice[i].W < mice[j].W && max <f[j].tot)
                {
                    max = f[j].tot;
                    k =j;
                }
            f[i].tot = max + 1;
            f[i].next = k;
        }
        max = 0;
        for(i=0; i<n; ++i)
            if(max < f[i].tot)
            {
                max = f[i].tot;
                k = i;
            }
        printf("%d\n",max);
        visit(k);
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        init();
        dp();
        return 0;
    }

    文章结束给大家分享下程序员的一些笑话语录: 很多所谓的牛人也不过如此,离开了你,微软还是微软,Google还是Google,苹果还是苹果,暴雪还是暴雪,而这些牛人离开了公司,自己什么都不是。

  • 相关阅读:
    HDU 3709 数位dp
    Educational Codeforces Round 64 (Rated for Div. 2)-C. Match Points
    POJ 1845乘法逆元+约数和
    POJ3696 欧拉定理
    NC24953 树形dp(最小支配集)
    Codeforces 1173 C 思维+模拟
    Codeforces 1324F 树形dp+换根
    codeforces-1285D(字典树)
    面向纯小白的CLion(C++)基于Windows的安装配置教程
    HDU-2825Wireless Password(AC自动机+状压DP)
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3087543.html
Copyright © 2011-2022 走看看