* Five questions glasses are spent
T1:
"Test Instructions" given a string, remove the suffix ly,er,ing once
"The ..."
T2
"Test Instructions" the weight of a given 1g,2g,3g,5g,10g,20g several, the total weight <=10^5, to find out how much quality
"The ..."
T2
Test instructions
Exercises
60 min n^4 Violence DP:
#defineMoD 1000000007intn,m,k,map[777][777],f[777][777];intMain () {FO (hopscotch); N=gi;m=gi;k=gi; FOR1 (i,n) FOR1 (j,m) map[i][j]=gi; f[1][1]=1; FOR1 (i,n) {FOR1 (j,m) {//printf ("(%d,%d):", i,j);FOR0 (l,i) FOR0 (R,J)if(map[l][r]!=Map[i][j]) {//if (l&&r) printf ("(%d,%d)", l,r);F[i][j]= (F[i][j]+f[l][r])%MoD; }//puts (""); } }//FOR1 (i,n) {////FOR1 (j,m) {//printf ("%d", f[i][j]); //}puts ("");// }printf"%d", F[n][m]); return 0;}
Positive solution
Czyz the layout of the machine room, is different from Elsewhere ....
Kong Yiji was so happy that he knocked two fingers on the counter and nodded, "Yes, yes!" ...... There are three things to be written about this question, you know? ”
First, it is obvious that the two-dimensional segment tree, the dynamic opening point can be done
It's also possible to maintain a balanced tree.
The positive solution is actually CDQ, but I will not cdq the division.
T4
Test instructions
Given a tree that is all letters, ask if there is a chain equal to the given string
Exercises
The data range is very interesting, consider an enumeration starting point of the BFS violence. Sort the discussion
For 20% of data, n≤1000.
For another 20% of the data, n≤10^4, and there is only one letter on the tree.
Expected complexity O (n)
For another 30% of the data, n≤10^4, and the tree is randomly generated.
Expected complexity O (NLOGN)
For another 30% of the data, n≤10^4, and the letters on the tree are randomly generated.
Expected complexity O (N^2/26/2)
However, in fact, this is quite virtual, so we look at the beginning and end of the number, which less from which to start BFS
And then it's over.
structedge{intTo,next;} e[23333];intcnt,last[10005];Charch[10005],tgt[10005];intf[10005][ -],dep[10005];voidLinkintAintb) {e[++cnt]= (Edge) {b,last[a]};last[a]=CNT; e[++cnt]= (Edge) {a,last[b]};last[b]=CNT;}structdata{inta,fa,d;};intn,m,_ds,_es,ds[10001],es[10001];BOOLBFsints) {Queue<data>Q; Q.push (data) {s,-1,1}); while(!Q.empty ()) {Data C=Q.front (); Q.pop (); for(intI=last[c.a];i;i=E[i].next) { if(e[i].to!=C.FA) {//printf ("from%d to%d\n", c.a,e[i].to); if(ch[e[i].to]==tgt[c.d+1]) {Q.push (data) {E[I].TO,C.A,C.D+1});//dep[e[i].to]=dep[c.first]+1; if(c.d+1==M)return true; } } } } return false;}BOOLDiffCharstr[]) { intT=strlen (str+1); FOR1 (i,t)if(i^1&&str[i]^str[i-1])return true; return false;}voidbfs1 () {}voidLuangao () {}intMain () {FO (alphabet); intt=gi; FOR1 (_,t) {intN=gi;BOOLflag=false; Memset (Last,0,sizeof(last)); Cnt=0; FOR1 (I,n-1){ intu,v;u=gi;v=gi; Link (u,v); }//BFS (1);scanf"%s", ch+1); scanf ("%s", tgt+1); N=strlen (ch+1), M=strlen (tgt+1); _ds=0; _es=0;//if (diff (TGT)) {FOR1 (i,n) {if(ch[i]==tgt[1]) ds[++_ds]=i; if(Ch[i]==tgt[m]) es[++_es]=i; } if(_ds<=_es) {FOR1 (l,_ds) {//cout<<ds[l]<<endl; if(BFS (Ds[l])) {flag=true; Break; } } } Else{FOR1 (i,m/2) Swap (tgt[i],tgt[m-i+1]); FOR1 (I,_es)//cout<<ds[l]<<endl; if(BFS (Es[i])) {flag=true; Break; }} printf ("Case #%d:%s\n", _,flag?"Find":"Impossible");//puts ("-------------");//}else{//Luangao ();// . } } return 0;}
The two empty functions. It was the same data that all the characters were, and I don't know how it went.
T5
"Test Instructions" given a non-negative matrix of n*m, the top-left corner to the lower-right path is worth the variance * (n+m-1) Minimum
Exercises
Consider a DP, which represents a (I,J) average value of K minimum variance, and then pretty well transferred
But the space is not good enough.
We're thinking about minimizing this equation.
So the first thing you can find is that s is the average time minimum.
Unfold his
If * (n+m-1), you can enumerate the last item, DP the first two
And then we can find out the answer.
Why is it possible to enumerate and what? Because the illegal and the answer will not be smaller than the exact
intn,m,a[ -][ -],f[ -][ -],ans=0x7fffffff;intMain () {FO (route); N=gi;m=gi; FOR1 (i,n) FOR1 (j,m) a[i][j]=gi; FOR0 (sum, (n+m-1)* -+1) {memset (F,0,sizeof(f)); FOR1 (i,n) FOR1 (j,m) {if(i==1) f[i][j]=f[i][j-1]; Else if(j==1) f[i][j]=f[i-1][j]; ElseF[i][j]=min (f[i][j-1],f[i-1][j]); intx=A[i][j]; F[I][J]+=x*x* (n+m-1)-x*sum*2; } ans=min (ans,f[n][m]+sum*sum); } cout<<ans; return 0;}
20160813 Morning Training Record