2019/8/29 school race simulation test report

A. Prepare (preparing.in)

Known \ (P \) is greater than \ (2 \) primes from \ (1 ... 2p \) selection \ (P \) number, such that \ (P \) number and can be \ (\ p) divided by the total number of program requirements.

Ideas :( 1 \ (the p-\ Le 30 \) )

Dynamic Programming hit the table.

#include<bits/stdc++.h>

long long Ans[]={0,0,0,8,0,52,0,492,0,0,0,64132,0,800048,0,0,0,137270956,0,1860277044,0,0,0,357975249028,0,0,0,0,0,1036802293087624,0};
int n,x;

int main()
{
    freopen("preparing.in","r",stdin);
    freopen("preparing.out","w",stdout);
    std::cin>>n;
    while(n--)
    {
        std::cin>>x;
        std::cout<<Ans[x]<<std::endl;
    }
    return 0;
}

Ideas :( 2 \ (the p-\ Le 1000 \) )

We first exclude select \ (1 ... p \) and select \ (p + 1 ... 2p \ ) In both cases , the remaining \ ((\ dbinom {p} {2p} -2) \) case.

Then is transformed into the \ (\ {1,2, ..., p-1, p \} \) selected \ (K \) number \ ((. 1 \ Le K <P) \) , in \ ( \ {p + 1, p + 2, ..., 2p-1,2p \} \) selected \ ((PK) \) number, the number of the selected groups and can be \ (P \) divisible the number of programs.

Easy to find, \ (\ {1,2, ...,. 1-P, P \} \) and \ (\ {p + 1, p + 2, ..., 2p-1,2p \} \) this sets the number of mold \ (p \) under the meaning is the same , one group may wish to discuss.

Suppose we selected in the first group \ (K \) number , referred to as \ (\ {A_1, A_2, ..., a_k \} \) .

We can all be expressed as \ (\ {(a_1 + d ) \ mod p, (a_2 + d) \ mod p, ... (a_k + d) \ mod p \} \) selected method classified as a Class wherein \ (D \ in [0, 1 P-] \) , then each class, the selected number and to \ (P \) remainder is \ (0 \) selected method accounts \ (1 / the p-\) , to \ (p \) of the remainder is \ (1 \) of the election law accounted for \ (1 / the p-\) , ..., to \ (p \) of the remainder is \ ((p- 1) \) of the election law accounted for \ (1 / the p-\) .

It can be introduced in the first set of selected \ (K \) all in one method selected from the group, and p \ (P \) of the remainder is \ (0 \) accounts \ (. 1 / P \) , for \ ( p \) of the remainder is (1 \) \ accounts of election law \ (1 / p \) , ..., to \ (p \) of the remainder is \ ((p-1) \ ) accounted for \ (1 / the p-\) . this is because, although we do not know the class number, but each type of accounting method selected for each of the remainder are unchanged, are \ (1 / the p-\) .

Now we consider the enumeration in the first set of selected \ (k \) number and to \ (p \) the remainder of .

Is assumed \ (0 \) , representing a first group was selected method \ (. 1 / P \) , then the second group of selected \ (PK \) number and p \ (P \) remainder is also must be \ (0 \) , representing a second group was selected method \ (. 1 / P \) , since the first and second selected from the group numbers are two independent events , so the above method is selected from the legal situation accounted method selected from the two groups \ (\ dfrac. 1} {2} {P ^ \) .

Is assumed \ (\ 1) , representing a first group was selected method \ (1 / P \) , then the second group of selected \ (PK \) number and p \ (P \) the remainder of the must is \ (p-. 1 \) , representing a second group was selected method \ (. 1 / P \) , since the first and second selected from the group numbers are two independent events , so that the above method is selected from legitimate accounting method selected from the two groups \ (\ dfrac. 1} {2} {P ^ \) .

...

Is assumed \ (. 1-P \) , representing a first group was selected method \ (. 1 / P \) , then the second group of selected \ (PK \) number and p \ (P \) of the remainder must be \ (1 \) , the second largest group, the total election law \ (1 / the p-\) , due to the election in the first and second groups in the number two independent events , so the above cases, legitimate election law accounting method selected from the two groups \ (\ dfrac. 1} {2} {P ^ \) .

Then the first set of selected \ (K \) number, a second set of selected \ ((PK) \) the number ratio of total legal method selected from the method of selection of \ (\ dfrac {1} { p ^ } 2 \ Times. 1 = P / P \) .

Easy to find when \ (k \) when changes in the above ideas can be generalized.

Then \ ((\ dbinom {p} {2p} -2) \) case, the accounting method selected from the legitimate \ (. 1 / P \) .

Coupled with the beginning of the two cases being excluded, the total number of programs:

\[\dfrac{\dbinom{p}{2p}-2}{p}+2\]

B. Scholarship (scholarship.cpp)

[USACO 2004 Mar] Financial Aid sponsored tuition

[TJOI2013] Scholarships

First, students on merit ascending sort , consider median enumeration.

It is worth noting that this question has no answer half of nature, not half,But I test when half as many as 70 points, the data is too water.

Pretreatment \ (L (i) \) indicates the student \ ([1, i) \ ) spent smallest \ (\ lfloor \ dfrac {n } 2 \ rfloor \) the total cost of a student, \ (R & lt (I ) \) empathy.

Then scan from left to right, looking to meet \ (L (i) + R (i) + cost (i) \ le F \) in the right-most students, it is the achievement answer.

#include<bits/stdc++.h>
const int SIZE=200005,INF=10005;
int n,C,F,L[SIZE],R[SIZE];

struct Stu
{
    int S,x;
    bool operator <(const Stu &u)const
    {
        return S<u.S;
    }
}stu[SIZE];
std::priority_queue<int>q;

int main()
{
    scanf("%d%d%d",&n,&C,&F);
    n/=2;
    for(int i=1;i<=C;i++)
        scanf("%d%d",&stu[i].S,&stu[i].x);
    std::sort(stu+1,stu+1+C);
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=stu[i].x;
        q.push(stu[i].x);
    }
    for(int i=n+1;i<=C;i++)
    {
        L[i]=sum;
        if(q.top()>stu[i].x)
        {
            sum-=q.top();
            q.pop();
            q.push(stu[i].x);
            sum+=stu[i].x;
        }
    }
    while(q.size())q.pop();
    sum=0;
    for(int i=C;i>=C-n+1;i--)
    {
        sum+=stu[i].x;
        q.push(stu[i].x);       
    }
    for(int i=C-n;i;i--)
    {
        R[i]=sum;
        if(q.top()>stu[i].x)
        {
            sum-=q.top();
            q.pop();
            q.push(stu[i].x);
            sum+=stu[i].x;          
        }
    }   
    int Ans=-1;
    for(int i=n+1;i<=C-n;i++)
    {
        if(L[i]+R[i]+stu[i].x<=F)Ans=stu[i].S;
    }
    printf("%d",Ans);
    return 0;
}

C. Chocolate (chocolate.cpp)

CF633F

Given a point right unrooted trees, find two disjoint chains and weights maximum.

DP immortal title .

After a lot of copies reference solution to a problem, and finally understand how DP.

We root for any node, DFS, maintain the following four values:

\ (Long (x) \) represents \ (x \) to the farthest leaves of its sub-tree, in other words, after the \ (x \) , and can continue to expand upward longest chain.

\ (DP1 (x) \) represents \ (X \) subtree chain length of the longest one.

\ (DP2 (x) \) represents \ (X \) subtree two longest chain length and do not intersect.

\ (DP3 (x) \) represents \ (x \) subtree chain and the other \ (x \) to a chain leaves the maximum length and, in other words, a chain and the other can continue scale-up and the maximum length of the chain.

When the transfer, all the possible values ​​of the respective cases generated, taking the optimal solution for the transfer.

About how transfer, I still have a lot of wonderful ideas, but lack of time, I can not write them down

#include<bits/stdc++.h>
#define LL long long
#define IL inline

const int SIZE=200005;
int head[SIZE],nex[SIZE],ver[SIZE],Tot;
LL weight[SIZE];

LL DP1[SIZE];//子树中选一条链的最大长度
LL DP2[SIZE];//子树中选两条链的最大长度和 
LL DP3[SIZE];//子树中选一条链和另一条到叶子节点的链的最大长度和
LL Long[SIZE];//到叶子节点的链的最大长度

void Link(int u,int v)
{
    nex[++Tot]=head[u];head[u]=Tot;ver[Tot]=v;
    nex[++Tot]=head[v];head[v]=Tot;ver[Tot]=u;
}

IL LL m2(LL A,LL B){return A>B?A:B;}
IL LL m3(LL A,LL B,LL C){return m2(A,B)>C?m2(A,B):C;}
IL LL m4(LL A,LL B,LL C,LL D){return m3(A,B,C)>D?m3(A,B,C):D;}
IL LL m5(LL A,LL B,LL C,LL D,LL E){return m4(A,B,C,D)>E?m4(A,B,C,D):E;}

void DFS(int u,int F)
{
    Long[u]=weight[u];
    DP1[u]=weight[u];
    LL o=0;
    for(int i=head[u];i;i=nex[i])
    {
        int v=ver[i];
        if(v==F)continue;
        DFS(v,u);
        LL Tem1=DP1[u],Tem3=DP3[u];
        DP1[u]=m3(DP1[u],DP1[v],Long[u]+Long[v]);
        DP2[u]=m5(DP2[u],DP2[v],Long[u]+DP3[v],Long[v]+Tem3,Tem1+DP1[v]);
        DP3[u]=m4(DP3[u],DP3[v]+weight[u],o+(weight[u]+Long[v]),Long[u]+DP1[v]);
        Long[u]=m2(Long[u],Long[v]+weight[u]);
        o=m2(o,DP1[v]);
    } 
}

int main()
{
    std::ios::sync_with_stdio(false); 
    int n,u,v;
    std::cin>>n;
    for(int i=1;i<=n;i++)std::cin>>weight[i];
    for(int i=1;i<n;i++){std::cin>>u>>v;Link(u,v);}
    DFS(1,0);
    std::cout<<DP2[1];
    return 0;
}

Guess you like

Origin www.cnblogs.com/TaylorSwift13/p/11431673.html