20,190,817 Exercise

ennn, today is the birthday of everyone 0x125E591 1S + .-of the XCC

T1: LG strange elevator.

S1: for each point to build a legitimate edges, the shortest run (ps: because it is not DP, the code is not on.).

T2: LG Nick task.

S2: Unfortunately exam card on this topic, see the last did not play even the violence associated with a given cross-section and a section of questions, naturally think of to do on the LG yesterday. Hungry cows   , then set the f [i] [ 0/1] is expressed as the i-th paragraph is selected from selected or not guarantee a minimum working time and a case where the front covering segment i are legitimate, f [i] [0] is enumerated before can cover section k i i is the interval f [i] [0] = max {f [k] [1]} of the transfer, f [i] [1] becomes hard to deal with, go to section k i does not cover section, and find the minimum cost v the cover Σk, f [i] [1] = max (f [i] [1], v + time [i]), v how finally found not to be found, and found that the latter choice can also affect the state of the front so clearly not push dp. looked explanations, indeed found to be pushed down, since the latter influence the state preceding the state. At this time, the recording is not the first task, it is f [i] = f [i + 1] +1, there are tasks to perform, f [i] = Σmax ( f [i], f [i + len]), recommended that the sample debugging, will naturally understand.

Summary: ① calm, positive solution will not fight violence .②MS: code once, think twice.

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
#define e exit(0)
#define R register
int n,k,id=1,sum[10010],f[10010];
struct bian{
    int L,v;
}len[10010];
bool cmp(bian a,bian b){return a.L>b.L;}
int main()
{
    freopen("LIGNJA.in","r",stdin);
    freopen("LIGNJA.out","w",stdout);
    scanf("%d%d",&n,&k);
    for(R int i=1;i<=k;++i){
        scanf("%d%d",&len[i].L,&len[i].v);
        ++sum[len[i].L];
    }
    sort(len+1,len+1+k,cmp);
    for(R int i=n;i>=1;--i){
        if(!sum[i])
            f[i]=f[i+1]+1;
        else{
            for(R int j=1;j<=sum[i];++j){
                f[i]=max(f[i],f[i+len[id].v]);
                ++id;
            }
        }
    }
    printf("%d",f[1]);
}

T5:LGP1233

S5: I do not know why the brain pumping test, required for dual-longest sequence without fall that he will seek to determine two requirements together ??? In fact, to think of the LG -friendly city will claim a sort finalized, another in. Based on this demand.

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
#define e exit(0)
#define R register
int n,q[5010],lenth;
struct bian{
    int L,W;
}len[5010];
bool cmp(bian a,bian b){
    if(a.L==b.L)
        return a.W<=b.W;
    else return a.L<b.L;
}
int find(int x)
{
    int l=1,r=lenth;
    while(l<r){
        int mid=(l+r)>>1;
        if(q[mid]<=x) r=mid;
        else l=mid+1;
    }
    return l;
}
int main()
{
    freopen("STICK.in","r",stdin);
    freopen("STICK.out","w",stdout);
    scanf("%d",&n);
    for(R int i=1;i<=n;++i)
        scanf("%d%d",&len[i].L,&len[i].W);
    sort(len+1,len+1+n,cmp);
    q[++lenth]=len[1].W;
    for(R int i=2;i<=n;++i)
    {
        if(len[i].W<q[lenth])
            q[++lenth]=len[i].W;
        else if(len[i].W>=q[lenth]){
            int id=find(len[i].W);
            q[id]=len[i].W;
        }
    }
    printf("%d",lenth);
    return 0;
}

PS: ①: a flag when an element is the same, another sort of small flag preamplifier, so monotonous stack length will seek to the development of small drops when longest sequences.

   ②: binary search to find the maintenance sequence monotonically decreasing the first smaller than it is written, with topics other requirements meant to pay attention to the right of the equal sign to the left of the relationship "than it is smaller than its big problem."

T3, T4 has the time to fix.

Guess you like

Origin www.cnblogs.com/xqysckt/p/11370152.html