2019.7.27 NOIP simulation test 9 summary reflection

First to organize topics

T1 effect Title: n digital and given a prime number as a modulus, an initial value of a variable x. Operation m times, so that each time multiplied by a random number x of the n, Q m x expectations of future operations.

The answer must be expressed as a fraction, multiply the output value of the denominator molecular inverse yuan.

 

Mathematics has been bad, this expectation is not fully understand. I looked up and test the range of data points suggest that deception has written two minutes to go.

In fact, I did not see the lie to divide the whole did not understand right, accidentally hit on one point. Correct answer is a primitive root of the conversion matrix multiplication into a sum matrix rapid power cycling. [Of course not get to know, and then look through someone else's blog to learn]

Leave a pit.

 

T2 effect Title: given a right side of a tree, each point has a weight referred to as a [i]. For a point, the distance to each point other point that point multiplied by the a [i] then summing, referred to as the degree of importance at this point b [i].

All points are given a [i] or b [i] of all points, determined is not given to a [i] or b [i].

 

To give a [i] seeking b [i]: a root change DP, cut.

Then look at the points a happy burst zero. Later research into the code, change the root of the equation push wrong. [Later changed when they are wrong again]

For given b [i] find a [i]: a Gaussian elimination, but in fact I've never written Gaussian elimination, toss a half roll to give up the commissioning of T3.

Later I learned find a [i] n solution is not Gaussian elimination. Consider the difference between every two b [i], b [j] neighbor, you will find them as boundaries for b [i] points while contribution of more than 1, for the other side of the point b [j] the contributions of many 1.

Try [i] b minus its father's b [fa [i]]. Look b [i] a [i] is the root of the subtree and siz [i], siz [i] to b [i] the contribution of less than 1 for b [fa [i]] contribution. See all the a [i] and the sum of this deduction portion siz [i], for the b [i] for the contribution ratio of b [fa [i]] contributions over. Then b [i] -b [fa [i]] = - siz [i] + (sum-siz [i]) = sum-2 * siz [i].

This allows the n-1 lists the root node for each non-formula. We then selected for the root node is set to [1] here, found b [1] = siz [2] + siz [3] + siz [4] + ... + siz [n]. b [1] 2-n have all siz [i], and the n-1 previous equation which we have listed a siz [i].

Then all the b [i] -b [fa [i]] add up, together with b [1] * 2, is all a [i] and the sum.

After getting sum we can consider the leaf nodes from the root to go all the way, the sum is substituted into the equation to get back to each siz [i], found siz [i] leaf node is a [i]. Then up processing by subtracting the son of siz siz current node, and finally get it is a. For the root node, it does not siz, but sum1 minus all siz is a [1], can be resolved in the same sentence dfs special inside look.

Code:

#include<iostream>
#include<cstdio>
using namespace std;
int t,n,opt;
int ver[200010],Next[200010],head[100010],tot;
int a[200010];
long long sum[200010],siz[200010],sum1,b[200010];
void add(int x,int y){
    ver[++tot]=y;
    Next[tot]=head[x];
    head[x]=tot;
}
void dfs(int x,int fa){
    siz[x]=a[x];
    for(int i=head[x];i;i=Next[i]){
        int y=ver[i];
        if(y==fa)continue;
        dfs(y,x);
        siz[x]+=siz[y];
        sum[x]+=sum[y]+siz[y];
    }
}
void dfs1(int x,int fa){
    for(int i=head[x];i;i=Next[i]){
        int y=ver[i];
        if(y==fa)continue;
        sum[y]=sum[x]+sum1-2*siz[y];
        dfs1(y,x);
    }
}
void dfs2(int x,int fa){
    for(int i=head[x];i;i=Next[i]){
        int y=ver[i];
        if(y==fa)continue;
        sum1+=b[y]-b[x];
        dfs2(y,x);
    }
}
void dfs3(int x,int fa){
    for(int i=head[x];i;i=Next[i]){
        int y=ver[i];
        if(y==fa)continue;
        sum[y]=(sum1-(b[y]-b[x]))/2;
        dfs3(y,x);
        siz[x]+=siz[y];
    }
    if(x!=1){
        a[x]=sum[x]-siz[x];
        siz[x]+=a[x];
    }
    else{
        a[x]=sum1-siz[x];
    }
}
void clear(){
    sum1=tot=0;
    for(int i=1;i<=n;i++)a[i]=b[i]=sum[i]=siz[i]=head[i]=0;
}
int main()
{
//    freopen("1.in","r",stdin);
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1,x,y;i<n;i++){
            scanf("%d%d",&x,&y);
            add(x,y),add(y,x);
        }
        scanf("%d",&opt);
        if(opt==0){
            for(int i=1;i<=n;i++){
                scanf("%d",&a[i]);
                sum1+=a[i];
            }
            dfs(1,1);
            dfs1(1,1);
            for(int i=1;i<=n;i++)printf("%lld ",sum[i]);
            printf("\n");
        }
        else{
            for(int i=1;i<=n;i++){
                scanf("%lld",&b[i]);
            }
            dfs2(1,1);
            sum1+=2*b[1];
            sum1/=(n-1);
            dfs3(1,1);
            for(int i=1;i<=n;i++)printf("%d ",a[i]);
            printf("\n");
        }
        clear();
    }
    return 0;
}

T3 subject to the effect: the starting point is (0,0), n gives the number of steps, each of which can take a step in one direction, and asked when parked in n steps (0,0) towards the program how many vertical and horizontal.

Each time any of the four constraints are given one:

There is no limit; non-negative x-axis only go axle; only go axes; only take x, y-axis, and a first non-negative axle quadrant.

 

No time when examination of the situation do not know why ringing off the hook calculate the number of combinations, just go write axis [in T2 self-made Gaussian elimination waste for a long time ......], write only take non-negative x-axis of the axle I do not get out of life and death, angrily wrote last four cases generic three-dimensional DP, actually took 50 points, the highest score three questions ...

For without limitation, ideas, and this question two days before the visit of the same. The number of steps to go around enumerator i, i-step is selected as to go around inside the n step [i] is an even number, selected from i / 2-step in which step i go left, go up step in which ni, the conclusion that formula:

C(n,i)*C(i,i/2)*C(n-i,(n-i)/2)

For only take x-axis non-negative axle, apparently no more than a left to go right away, similar to the problem can not be more than the stack into the stack, namely the number of Cattleya. Because the total walking from right to left is n, find cat (n / 2).

For only take x, y-axis, and a first non-negative axle quadrant, will find here is no more than walking to the left limit right away, go down and go up can not exceed. Enumerate a few steps to go about [i] i is an even number, while limiting around and up and down. That is, for each i, obtains cat (i / 2) * cat ((ni) / 2) * C (n, i)

Finally, for the axis can go, see the data range n <= 1000 consideration DP.

DP is pushed from front to back, then set a program ans array represents i go back to step origin. For an n-step embodiment, can be split into two processes: i-step away from the origin, except that no intermediate step i easily go back to the origin + ni steps back to the origin. The number in front of this scheme is to step i cat (i / 2-1), minus one is because it is possible to go back to square one, and then let it go ahead i step out of catalan origin after the number represented [ step back], the significance of such catalan back up to a point to come out of this, to meet the conditions. Ni casually walk step back to square one, that is, ans [ni]. Enumerate all i [i] to do an even do not leak. DP equation: ans [i] = Σans [j] * car (j / 2-1).

Inverse factorial factorial out to pretreatment, so that O (1) number and the number of combinations is calculated catalan [I changed when the first punched question retarded decomposition of the quality factor, T than the original lower sub 50].

Here are the four cases discussed finish, this question is a four-in-question.

Code:

#include<iostream>
#include<cstdio>
using namespace std;
const long long mod=1000000007;
int n,opt;
long long rec[200010],inv[200010],f[200010];
long long ks(long long x,long long k){
    long long num=1;
    while(k){
        if(k&1)num=num%mod*x%mod;
        x=x%mod*x%mod;
        k>>=1;
    }
    return num;
}
void work(int x){
    inv[0]=rec[0]=rec[1]=1;
    for(int i=2;i<=x;i++)rec[i]=(rec[i-1]%mod*(long long)i%mod)%mod;
    inv[x]=ks(rec[x],mod-2);
    for(int i=x-1;i>=1;i--)inv[i]=(inv[i+1]%mod*(long long)(i+1)%mod)%mod;
}
long long cat(long long x){
    if(x==0)return 1;
    return((rec[2*x]*inv[x])%mod*inv[x+1])%mod;
}
int main()
{
    scanf("%d%d",&n,&opt);
    work(n);
    if(opt==1){
        printf("%lld",cat(n/2));
    }
    else if(opt==2){
        f[0]=1;
        for(int i=2;i<=n;i+=2){
            for(int j=2;j<=i;j+=2){
                f[i]=(f[i]+f[i-j]%mod*4%mod*cat(j/2-1)%mod)%mod;
            }
        }
        printf("%lld",f[n]);
    }
    else if(opt==3){
        long long ans=0;
        for(int k=0;k<=n;k+=2){
            long long ans1=1;
            ans1=ans1*cat(k/2)%mod;
            ans1=ans1*cat((n-k)/2)%mod;
            ans1=ans1*rec[n]%mod*inv[k]%mod*inv[n-k]%mod;
            ans=(ans+ans1)%mod;
        }
        printf("%lld",ans);
    }
     ;else {
         Long  Long ans = 0 ;
        for ( int k = 0 ; k <= n; k + = 2 ) {
             Long  Long ANS1 = 1 ; 
            ANS1 = ANS1 * rec [N]% v * inv [k / 2 ]% v * inv [k / 2 ]% v * inv [(nk) / 2 ]% v * inv [(nk) / 2 ]% v ; 
            ans = (ANS + ANS1)% v; 
        } 
        Printf ( " % lld " , ANS); 
    } 
    Return  0 
}

 

 

Reflection ... thought, wrote a travelogue it. Then to here.

 

Guess you like

Origin www.cnblogs.com/chloris/p/11256661.html