• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            心如止水
            Je n'ai pas le temps
            posts - 400,comments - 130,trackbacks - 0
            此題使用動態規劃。首先做一些預處理:排序。按體重由小到大排序,相同體重的按IQ遞減排序。動態規劃的狀態轉移方程為d[i]=max{d[j]+1|j<i,a[j].weight<a[i].weight,a[j].iq>a[i].iq}。
            以下是我的代碼:
            #include<stdio.h>

            //#define LOCAL

            typedef 
            struct
            {
                
            long id,weight,iq;
            }type;
            const long maxn=1007;
            long n,ans,pos,d[maxn],f[maxn],tmp[maxn];
            type a[maxn];
            void Qsort(long begin,long end)
            {
                
            long i=begin,j=end,mid1=a[(begin+end)/2].weight,mid2=a[(begin+end)/2].iq;
                type t;
                
            do{
                     
            while(a[i].weight<mid1||(a[i].weight==mid1&&a[i].iq>mid2)) i++;
                     
            while(a[j].weight>mid1||(a[j].weight==mid1&&a[j].iq<mid2)) j--;
                     
            if(i<=j)
                     {
                        t
            =a[i];a[i]=a[j];a[j]=t;
                        i
            ++;j--;
                     }
                }
            while(i<=j);
                
            if(i<end)   Qsort(i,end);
                
            if(j>begin) Qsort(begin,j);
            }
            int main()
            {
                #ifdef LOCAL
                freopen(
            "data.in","r",stdin);
                freopen(
            "data.out","w",stdout);
                
            #endif
                n
            =0;
                
            while(scanf("%ld%ld",&a[n+1].weight,&a[n+1].iq)==2)
                {
                   n
            ++;
                   a[n].id
            =n;
                }
                
            //  Input
                Qsort(1,n);
                
            //  Qsort
                for(long i=1;i<=n;i++)
                {
                   d[i]
            =1;
                   f[i]
            =0;
                }
                
            //  Init
                for(long i=1;i<=n;i++)
                  
            for(long j=1;j<i;j++)
                    
            if(a[i].weight>a[j].weight&&a[i].iq<a[j].iq&&d[i]<d[j]+1)
                    {
                       d[i]
            =d[j]+1;
                       f[i]
            =j;
                    }
                
            //  DP
                ans=0;pos=0;
                
            for(long i=1;i<=n;i++)
                  
            if(d[i]>ans)
                  {
                     ans
            =d[i];
                     pos
            =i;
                  }
                tmp[
            1]=a[pos].id;
                
            for(long i=2;i<=ans;i++,pos=f[pos])
                  tmp[i]
            =a[f[pos]].id;
                printf(
            "%ld\n",ans);
                
            for(long i=ans;i>=1;i--)
                  printf(
            "%ld\n",tmp[i]);
                
            //  Output
            return 0;
            }


            posted on 2010-02-08 14:19 lee1r 閱讀(713) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:動態規劃
            久久精品国产一区二区三区 | 亚洲国产一成久久精品国产成人综合 | 久久中文字幕人妻丝袜| 亚洲中文字幕久久精品无码喷水 | 伊人久久五月天| 日产精品久久久久久久| 99久久精品免费看国产| 久久天天躁夜夜躁狠狠| 婷婷久久综合九色综合98| 欧美激情精品久久久久久| 久久香蕉超碰97国产精品| 久久久精品国产Sm最大网站| 久久久久AV综合网成人| 久久se精品一区二区影院| 久久精品国产亚洲AV香蕉| 久久这里只有精品首页| 久久99精品国产麻豆婷婷| 久久亚洲国产精品一区二区| 日韩精品久久久肉伦网站 | 91亚洲国产成人久久精品| 久久99久久99精品免视看动漫| 久久综合视频网站| 久久精品国产精品亚洲人人| 91久久精品视频| 久久91亚洲人成电影网站| 精品人妻久久久久久888| 亚洲午夜久久久影院| 久久人人爽人人爽人人片AV东京热 | 午夜天堂av天堂久久久| 久久亚洲精品无码aⅴ大香| 久久精品中文字幕一区| 久久久艹| 久久无码国产专区精品| 久久99久久99精品免视看动漫| 国产精品久久久久久五月尺| 亚洲精品乱码久久久久久不卡| 日本国产精品久久| 国产精品乱码久久久久久软件| 国产成人精品久久| 91精品国产综合久久婷婷| 国产精品美女久久久久网|