Heim  >  Artikel  >  Web-Frontend  >  Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present_html/css_WEB-ITnose

Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:53:14953Durchsuche

最长上升子序列,这种水题还是一眼就能看出来的。



题目大意:

主人公想在一张w*h的明信片外套信封。他有n个信封,每个信封的长宽给出,问最多能套多少层。给出从小到大的顺序。


解题思路:

最长上升子序列,只不过是记忆路径。



下面是代码:

#include <set>#include <map>#include <queue>#include <math.h>#include <vector>#include <string>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <cctype>#include <algorithm>#define eps 1e-10#define pi acos(-1.0)#define inf 107374182#define inf64 1152921504606846976#define lc l,m,tr 0 ? (x) : -(x))#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))#define clearall(A, X) memset(A, X, sizeof(A))#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))#define memcopyall(A, X) memcpy(A , X ,sizeof(X))#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )#define min( x, y )  ( ((x) w&&envelopes[cnt].h>h)cnt++;    }    if(cnt==0)    {        puts("0");        return 0;    }    clearall(pre,-1);    sort(envelopes,envelopes+cnt);    int maxnum=1,maxp=0;    dp[0]=1;    for(int i=1; i<cnt i int max1="-1,mp=-1;" for j="i-1;">=0; j--)        {            if(envelopes[j].w<envelopes max1="dp[j];" mp="j;" dp pre if>maxnum)        {            maxnum=dp[i];            maxp=i;        }    }    printf("%d\n",maxnum);    output(maxp);    return 0;}</envelopes></cnt></algorithm></cctype></iostream></stdlib.h></string.h></stdio.h></string></vector></math.h></queue></map></set>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn