2019.8.26 Summary

T1 GCD and XOR 100/100

The meaning of problems

Law title, hit the table to find the law can be found

a xor b >= a - b >= gcd(a, b),

If a xor b = gcd (a, b) = c is c = a - b

Analyzing a multiple enumeration b to c, and

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn=1000010;
long long ans[maxn+10];
int T,n;
int main(){
    for(int c=1;c<=maxn;++c){
        for(int a=c*2;a<=maxn;a+=c){
            int b=a-c;
            if((a^b)==c) ans[a]++;
        }
    }
    for(int i=1;i<=maxn;++i){
        ans[i]+=ans[i-1];
    }
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        printf("%d\n",ans[n]);
    }
    return 0;
}

T2 30/0


The math exam to fight violence of 2x2, 2x2 and found the wrong pushed this case, burst 0.

Resolve

Dyed black and white grid on the board. Manhattan distance even number: the same parity.

Enumeration several colors assigned to white cells, the number of combinations can be calculated.

Note pretreatment time is quite ample.

In order not to repeat count, with strict considering the enumeration colors i, j we then enumerate assigned to the white seed set. Set set white and black are set size s1, s2, then the contribution of this allocation scheme is the answer \ (C ^ K_i \) \ (C ^ K_i \) \ (F_ {S1, J} \) \ (F_ S2 {,} ij of \) \ (J! \) \ ((ij of)! \)

\ (f_ {i, j} \) represents the number of the second type Stirling, i represents the number allocated to the set program number j.

\(f_{i,j}\) = \(f_{i-1,j-1}\) + \(f_{i-1,j}\) \(\times j\)

\(f_{0,i}\) = \(0^i\)

These things can be pretreated.

Note the border to a good start, or n = 1, m = 1 case will be wrong.

Time complexity $ O (n ^ 2 m ^ 2 + qK ^ 2) $.

Code

#include<bits/stdc++.h>
using namespace std;
const long long p=1000000007;
int T,n,m,k,s1,s2;
long long c[410][410],f[410][60],fact[410],ans;
bool mape[25][25];
int main(){
    scanf("%d",&T);
    c[0][0]=1;c[1][0]=c[1][1]=1;
    for(int i=2;i<=405;++i){
        for(int j=0;j<=i;++j){
            c[i][j]=(c[i-1][j]+c[i-1][j-1])%p;
        }
    }
    f[0][0]=1;
    for(int i=1;i<=405;++i){
        for(int j=1;j<=50&&j<=i;++j){
            f[i][j]=(f[i-1][j]*j+f[i-1][j-1])%p;
        }
    }
    fact[0]=1;
    for(int i=1;i<=405;++i){
        fact[i]=(long long)i*fact[i-1]%p;
    }
    while(T--){
        scanf("%d %d %d",&n,&m,&k);
        s1=0,s2=0;
        for(int i=1;i<=n;++i){
            for(int j=1;j<=m;++j){
                mape[i][j]=(i&1)^(j&1);
                s1+=mape[i][j];
                s2+=1^mape[i][j];
            }
        }
        ans=0;
        for(int i=1;i<=k;++i){
            for(int j=0;j<=i;++j){
                (ans+=(((((c[k][i]%p*c[i][j])%p*f[s1][j])%p*f[s2][i-j])%p*fact[j])%p*fact[i-j])%p)%=p;
            }
        }
        printf("%lld\n",ans%p);
    }
     
    return 0;
}

T3 10/10

The meaning of problems

Gives the two roots of two trees, let them ask the same shape you want to add a few nodes.

This question is not learned, exam direct input 2,10 pts

Resolve

Tree Dynamic Programming.

How to calculate the distance value of two sub-trees? Calculating two subtrees mutual distance value between all sons, then bipartite graph can be matched optimally.

二分图最优匹配可以用网络流做,也可以KM。

对于二叉树的数据,直接枚举和哪个儿子匹配也可。

代码(以后来写)

Guess you like

Origin www.cnblogs.com/donkey2603089141/p/11415359.html