6.15 Exam Revision + Summary

Source: Internet
Author: User
Tags mul

Yesterday, the test collapsed Qaq

Almost full of violence, but no egg.

Because as long as a off a problem is higher than I, higher than I also at least a dropped a problem qaq

Feel the slightest hint of sorrow and sunshine

Looks like the THUSC finally listens to the lecture the people almost all a has two questions

Looks like my thusc is just RP.

First question

Obviously choose the color of the least color, set the number of colors m

Consider the number of scenarios where there is a point, set this point to K distance I point

The number of scenarios is (N-1-I)! /((m-i)!*j!*k!...... ) J,k etc. is the color number of other colors

The general scheme is also very good, so that we can calculate the contribution of each point to the desired

To do this is O (n^2)

And then we consider T=1 's violent division.

It is not difficult to find problems to be transformed into maintenance arithmetic progression and

This is a classic problem of chunking, when tolerance d>sqrt (n), violence is sqrt (n)

When D<SQRT (n) We can pre-process the answer, each time the change of violence to sqrt (n) d is modified once

The time complexity is O (n*sqrt (n))

I only thought about it at the time of the exam, so I had 50 points.

Then we noticed that when t>1, M<=N/2

Then a point to K distance per point, probability at least/2

It is not difficult to find that when we are very large, the probability is very small for the accuracy of the request will not have an impact, so that we do not have to calculate

And then t=1 us to maintain the sub-block, t>1 when we were violent about 50-100 of the answers to the calculation

Qaq sad mulberry thing is after the exam to change the problem I just add a word to my program, and then a Qaq

Sum up why didn't you see every probability to/2 this thing

Because I'm not going to roll past the probability of Qaq. I was taking LN and exp back.

So I can't see anything.

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < Cstdlib> #include <cmath>using namespace std; const int Oo=0x7fffffff;const int Maxn=100010;int n,m,x,y,type,mn,blo;int t,k,d,c[maxn];int val[maxn];int S[330][330]; Long double JC[MAXN];                 void Get_pre () {for (int i=1;i<=blo;++i) {//step for (int. j=1;j<=i;++j) {for (int k=j;k<=n;k+=i) {            S[I][J]=S[I][J]+VAL[K]; }}} return;}    int main () {scanf ("%d%d", &n,&m);    for (int i=1;i<=n;++i) scanf ("%d", &val[i]);    jc[0]=0;    for (int i=1;i<=n;++i) jc[i]=jc[i-1]+log (i);    blo= (int) (sqrt (n));    Get_pre ();        while (m--) {scanf ("%d", &type);            if (type==1) {scanf ("%d%d", &x,&y);            int v=y-val[x];            Val[x]=y;                for (int i=1;i<=blo;++i) {int q= (x-1)%i+1;            S[i][q]+=v; }}else{scanf ("%d%d%d", &AMP;T,&AMP;K,&AMP;D);            for (int i=1;i<=t;++i) scanf ("%d", &c[i]);                if (t==1) {int ans=0;                    if (D>blo) {ans=val[k];                    for (int i=k+d;i<=n;i+=d) ans+=val[i];                for (int i=k-d;i>=1;i-=d) ans+=val[i];                    }else{int q= (k-1)%d+1;                ANS=S[D][Q];                }printf ("%d", ans);            printf (". 0000\n");                }else{Mn=oo;long double p=0;                a long double ans=0;                    for (int i=1;i<=t;++i) {mn=min (mn,c[i]);                P=p-jc[c[i]];                } long double sum=p+jc[n-1]; int cnt=0;                P=P+JC[MN];                    for (int i=k+d;i<=n;i+=d) {cnt++;                    if (cnt>100) break;                    if (cnt>mn) break;                    a long double tmp=p-jc[mn-cnt]+jc[n-1-cnt]-sum; Ans=ans+eXP (TMP) *val[i];                }cnt=0;                    for (int i=k-d;i>=1;i-=d) {cnt++;                    if (cnt>100) break;                    if (cnt>mn) break;                    a long double tmp=p-jc[mn-cnt]+jc[n-1-cnt]-sum;                ANS=ANS+EXP (TMP) *val[i];                }ANS=ANS+VAL[K];            printf ("%.4lf\n", (Double) (ans)); }}}return 0;}

Second question

First, k=0 is the topic of the universal group.

When you k=1, you can find the diameter.

K=n,c=1 the problem into a chain that divides the tree into the least.

And then I started DP, and the last 35 minutes rolled.

The test heel LYC exchange a bit of my DP practice just add k one dimensional more tree backpack can be a qaq

We know that K=n is the time to divide the least chain

So in fact, the problem is to divide the tree into K bar disjoint chain so that the chain of Benquan and maximum

It is not difficult to find that this problem has the nature of DP, do the backpack on the tree can be

When the shift is over, sort the discussion Qaq

The analysis of time complexity is the same as HAOI2015 's, O (NK) Qaq

#include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include < Algorithm>using namespace Std; const int Maxn=10010;const int Oo=0x7fffffff/3;int n,k,c;int u,v,w,ans;int h[maxn],cnt=0;int sz[maxn];int f[2010][2010] [2];int tmp[2010][2];struct edge{int to,next,w;} g[maxn<<1]; void Add (int x,int y,int z) {++cnt; G[cnt].to=y; G[CNT].NEXT=H[X]; g[cnt].w=z;h[x]=cnt;}    void read (int &num) {Num=0;char Ch=getchar (); while (ch< '! ')    Ch=getchar (); while (ch>= ' 0 ' &&ch<= ' 9 ') num=num*10+ch-' 0 ', Ch=getchar ();}    void DP (int u,int fa) {sz[u]=1;f[u][0][0]=0;f[u][1][1]=-c;        for (int k=h[u];k;k=g[k].next) {int v=g[k].to;        if (V==FA) continue;        DP (V,u);        for (int i=0;i<=sz[u]+sz[v];++i) Tmp[i][0]=tmp[i][1]=-oo;                                 for (int i=0;i<=sz[u];++i) {for (int j=0;j<=sz[v];++j) {int now=i+j;            Tmp[now][0]=max (Tmp[now][0],f[u][i][0]+f[v][j][0]);    if (now>=1) Tmp[now-1][0]=max (TMP[NOW-1][0],F[U][I][1]+F[V][J][1]+G[K].W+C);                Tmp[now][1]=max (TMP[NOW][1],F[U][I][0]+F[V][J][1]+G[K].W);                         Tmp[now][1]=max (Tmp[now][1],f[u][i][1]+f[v][j][0]);        }}sz[u]+=sz[v];            for (int i=0;i<=sz[u];++i) {F[u][i][0]=max (f[u][i][0],tmp[i][0]);        F[u][i][1]=max (f[u][i][1],tmp[i][1]); }} return;        int main () {while (scanf ("%d%d%d", &n,&k,&c) ==3) {memset (h,0,sizeof (h)); cnt=0;ans=0;            for (int i=1;i<n;++i) {read (u); Read (v); Read (w);            u++;v++;            Add (u,v,w); add (v,u,w);        Ans+=w;        } memset (F,-0x3f,sizeof (f));        DP (1,-1);ans<<=1;        int s=0;            for (int i=0;i<=k;++i) {S=max (s,f[1][i][0]);        S=max (s,f[1][i][1]);        }ans-=s;    printf ("%d\n", ans); }return 0;}

Third question

The subject of good God! It took me half a day to figure it out

First we notice that if we give each letter a random value, we calculate the determinant.

It is not difficult to find that if the determinant is not 0 in the sense of modulo 2, it must be no, otherwise it may be yes or no

Then some strange theorem points out that in the field F randomly brought in and calculated determinant, the probability of determinant 0 is d/f

F is the size of the domain, so we just need to find a large enough domain F to

Obviously, it can't be a 2 residual system, because the size is 2.

It is advisable to construct a K-quadratic polynomial with coefficients of 0 or 1, and let him take the form of an irreducible polynomial m, constituting a polynomial ring

The size of the field is obviously 2^k

So we can give each letter a polynomial and calculate the determinant.

Because it is done in the sense of modulo 2, the operation of the polynomial can be accelerated by the bitwise operation

Set the polynomial f,g

Then F-g=f+g=f^g

For F*g we can take a similar fast multiplication method to decompose G and multiply F by

When we calculate the determinant, because we are only concerned about whether it is 0, we convert the division into multiplication

As for the M modulus, i.e. f=min (F,F-M)

namely F=min (F,F^M)

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < cstdlib>using namespace Std;const int m=0x20000035; const int Maxn=52;int t,n;int val[1010];int A[maxn][maxn];char s[maxn][maxn][112];    void Read (char *s) {char C; while (C=getchar (), c!= ' + ' && (c< ' A ' | | C> ' z ') && (c< ' 0 ' | |    C> ' 9 '));    * (s++) =c; while (C=getchar (), c== ' + ' | | (c>= ' A ' &&c<= ' z ') | | (c>= ' 0 ' &&c<= ' 9 '))    * (s++) =c; * (s++) = ' + '; *s=0;}    int mul (int a,int b) {int s=0;        while (b) {if (b&1) s=s^a;    A<<=1;a=min (a,a^m);b>>=1; }return s;}    int Get_val (char *s) {int Now=0,t=1,len=strlen (s);        for (int i=0;i<len;++i) {if (s[i]== ' + ') now^=t,t=1;        else if (s[i]>= ' a ' &&s[i]<= ' Z ') T=mul (T,val[s[i]]);    else t=s[i]-' 0 '; }return now;}        BOOL Gauss () {for (int i=1;i<=n;++i) {int k=0,to;        for (To=i;to<=n;++to) if (a[to][i]) break;     if (to>n) return 1;   if (to!=i) for (int j=1;j<=n;++j) swap (a[i][j],a[to][j]);                for (int j=i+1;j<=n;++j) {if (A[j][i]) {int x=a[i][i],y=a[j][i];                for (int k=i;k<=n;++k) {A[j][k]=mul (a[j][k],x) ^mul (a[i][k],y); }}}}return 0;}    BOOL Judge () {for (int i= ' a '; i<= ' z '; ++i) Val[i]=rand ();        for (int i=1;i<=n;++i) {for (int j=1;j<=n;++j) {a[i][j]=get_val (s[i][j]); }}return Gauss ();}    int main () {srand (809495818);    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);        for (int. i=1;i<=n;++i) for (int j=1;j<=n;++j) read (s[i][j]);        BOOL Flag=true; for (int t=10; t&& (Flag=judge ());        t--);        if (flag) printf ("yes\n");    else printf ("no\n"); }return 0;}

It was a big mistake at the test.

First the first question is very close to the positive solution, but the probability of diminishing when the t>1 is not noticed is very fast (because I get the log after exp goes back)

So no a drop

As for the second question has successfully turned the problem into a split-chain problem, and know that K no limit when the DP approach

But the exam did not continue to think, and thus did not find that as long as the addition of one dimension k can do the same DP

The third question, Qaq.

6.15 Exam Revision + Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.