[Exam reflection] 1218 provincial election simulation 2: warn

CCF NOI 2018 Tips:

Do title 10 million, reading the first question.

Multi measured not empty, burst zero two lines of tears.

The CCF's warning to the foolish King himself. T1 Sets of empty did not clean out the AC code is zero burst.

Two dozen IOI competition system a score of 170/135. If I can barely cleared and skyh flat.

But not if. The result is "food"

Ten million long memory.

Or habitual use of "array initial value is 0 no assignment" feature, but not completely emptied led to the collapse.

 

Up three questions, T1 is noip simulation test the original question 3, did not see it, it will not do. But to change the subject.

Then put a weakening adaptation of "infinite loop", without thinking began to write (my decadent decadent solution to a problem so serious), the sample had to pay, and then I thought I was the AC.

Shoumo a sample test data of a group of several, all over, very kx.

Because of the heavy traffic problem file again, in fact, he finished 40 minutes.

Then skipped to look at the "infinite loop" miku beside me pain to write plug dp, he feels so poor.

But in fact, the poor are my good and bad people there and 40 minutes. . .

Then it was over. T2 no idea a little, T3 wrote a full array.

Since then T1 has felt the AC, T2 what do not, then I can only think part of T3 points ah.

See $ a_i $ that only 2 points, so he found the state had a lot of redundancy, some look exactly the same full array do not need to enumerate many times ah.

Then continue to optimize the idea, anyway, the rest of the time nothing to do, try their luck faith to write a memory search seizure of how much is how much ah

Expect to score 10 points I do not think, looking at the AC should be equivalent to a T1 and empty T2, I do not know where to go.

So I went back to the LCA LCT2 topics that question the AC (prefix differential maintenance interval and the interval operation query Fenwick tree is really handsome ah!)

Tune then I had no pot of Fenwick tree, subject point numbering starts at 0, code, there are a forgotten +1 unscrupulous people out of the question

Then the test is over, surprised to find himself T1TLE0 up.

I was a fool 2333

 

T1: rail construction

Effect Title: Grid FIG. With a number of circuit complete coverage of all non-barrier grid, some key points, resulting in a straight line when the price at the critical point of the path. Q. minimum cost. Multiple sets of test data . n, m <= 25

Simplified adaptation of " infinite loop ." Only L-type and straight.

We first of all split into four points represented vertically and horizontally, and FIG. Among the stained white black even source connected sink.

Each grid point even the source of a 2-flow, even the sink is. If so full flow chart is forming a loop.

Consider how Flip / breaking straight tracks. Let's assume that all the tracks are right and upward angle is now 90 degrees.

Angle is 90 degrees is curved tracks, the cost is zero. Angle of 180 degrees is a straight rail, the cost is zero.

We found that if a rail rotated 180 degrees, flip angle is still 90 degrees, the curved rails, no contribution to the cost. So right to left, not even down on the edge, flow 0 1 fee.

If the flip of a rail 90 degrees, then after flip angle is 180 degrees, that is, the straight tracks, there is a price. So even down the right side, even on the left side, traffic costs 1 1.

Then that is a minimum cost maximum flow.

 1 #include<cstdio>
 2 int min(int a,int b){return a<b?a:b;}
 3 int A[28][28],n,m,t,o[28][28][4],pc,ec=1,S,E,cost,maxflow,out,in,al[2555];
 4 int fir[2555],l[666666],to[666666],w[666666],c[666666],q[6666666],iq[2555],dt[2555];
 5 void link(int a,int b,int W,int C){l[++ec]=fir[a];fir[a]=ec;to[ec]=b;w[ec]=W;c[ec]=C;}
 6 void con(int a,int b,int W,int C){if(a==0||b==0)return;link(a,b,W,C);link(b,a,0,-C);}
 7 bool bfs(){
 8     for(int i=1;i<=pc;++i)dt[i]=1234567890,al[i]=0;q[1]=S;dt[S]=0;
 9     for(int h=1,t=1;h<=t;iq[q[h]]=0,++h)for(int i=fir[q[h]];i;i=l[i])if(w[i]&&dt[to[i]]>dt[q[h]]+c[i]){
10         dt[to[i]]=dt[q[h]]+c[i];
11         if(!iq[to[i]])iq[q[++t]=to[i]]=1;
12     }return dt[E]!=1234567890;
13 }
14 int dfs(int p,int flow){int r=flow;
15     if(p==E)return r;al[p]=1;
16     for(int i=fir[p];i&&r;i=l[i])if(dt[to[i]]==dt[p]+c[i]&&!al[to[i]]&&w[i]){
17         int x=dfs(to[i],min(r,w[i]));
18         if(!x)dt[to[i]]=1234567890;
19         w[i]-=x;w[i^1]+=x;r-=x;cost+=x*c[i];
20     }al[p]=0;return flow-r;
21 }
22 main(){freopen("railway.in","r",stdin);freopen("railway.out","w",stdout);
23     scanf("%d",&t);
24     while(t--){
25         scanf("%d%d",&n,&m);
26         #define O(x) o[i][j][x]
27         for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)scanf("%d",&A[i][j]);
28         for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(A[i][j])for(int k=0;k<4;++k)O(k)=++pc;
29         S=++pc;E=++pc;
30         for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(A[i][j])
31             if (i + j & 1 ) with (S, O ( 0 ), 1 , 0 ), with (S, O ( 1 ), 1 , 0 ), with (A ( 0 ), A ( 2 ), 1 , 0 ) with (A ( 1 ), A ( 3 ), 1 , 0 ), with (A ( 0 ), A ( 3 ), 1 , A [i] [j] - 1 ) to (A ( 1 ) , A ( 2 ), 1 , A [i] [j] - 1 );
32              else with (A ( 0 ), E, 1,0),con(O(1),E,1,0),con(O(2),O(0),1,0),con(O(3),O(1),1,0),con(O(3),O(0),1,A[i][j]-1),con(O(2),O(1),1,A[i][j]-1);
33         for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(i+j&1)if(A[i][j])
34             con(O(0),o[i-1][j][2],1,0),con(O(1),o[i][j+1][3],1,0),con(O(2),o[i+1][j][0],1,0),con(O(3),o[i][j-1][1],1,0);
35         while(bfs())maxflow+=dfs(S,66666);
36         for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(A[i][j])if(i+j&1)out+=2;else in+=2;
37         if(in!=out||in!=maxflow)puts("-1");else printf("%d\n",cost);
38         for(int i=1;i<=pc;++i)fir[i]=0;maxflow=out=in=cost=pc=0;ec=1;
39         for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)for(int k=0;k<4;++k)o[i][j][k]=0;
40     }
41 }
View Code

 

T2: Rodeo game

Goo? What points will not be part of the solution to a problem to write about?

 

T3: combinatorics

Title effect: the given number of columns a, for all of its arrangement b seeking prefix and obtain s, seeking $ \ sum \ limits_ {b = permutation (a)} \ frac {\ prod \ limits_ {i = 2} ^ {m!} {n} s_i} $. m is a sum. n <= 100, m <= 1000

This formula is still the question of when there is a lot of meaning, with the meaning of the formula guess sometimes more convenient.

It can be seen in the form of this equation can be rearranged more like a few (thanks %%% LNC correct definitions). So to think from the perspective of the arrangement.

Here is a prefix and the denominator, but still missing a $ s_1 $ annoying people, put it back up.

Consider the outer sum under $ permutation symbol (a) $ meaning, is in turn elected from one of more stuff in it.

The m balls are arranged, each $ b_i $ th, a position that appears we known each ball, which is arranged in the order p.

Sticky solution to a problem or need. It is too correct unexplained. (In fact, too lazy to hand-written again)

The above probability in any order m for balls. So is $ m! $ Multiplied by the probability of each is a legitimate program number.

In particular, because the topics formula yard and not $ s_1 $, so we do not limit it one of the most forward position last ball, which happens to be the number 1.

This meaning is finally out, and now we throw away the original formula containing difficult to optimize the arrangement of enumeration, only from meaning, to discover new complexity correct formula.

First, give priority to special elements - the most forward position that is not necessarily the kind of balls numbered 1.

We enumerate it in the end is what kind of, it's kind of a temporary number to be last, one of the earliest position where the ball appeared to pos.

By definition, behind it there should be no other kind of ball No. 1, but the direct solution is difficult, let us consider the inclusion-exclusion.

Provided f (x) is exactly 1 x bulbs behind the ball pos. So we need to solve is f (0). Because we have said it is the last.

No direct solution, then solved "at least." Provided g (x) is at least 1 x bulbs behind the ball pos.

The next %%% LNC rigorous proof of inclusion and exclusion.

Where x is a variable that should not really be expressed in several, but rather a collection to represent what kinds of concrete.

Because for different species, though their size (number of species) the same, but they have different transfer value, so just say the set size is not rigorous.

By definition, there is $ g (x) = \ sum \ limits_ {x \ subseteq y} f (y) $

The subset inversion, $ f (x) = \ sum \ limits_ {x \ subseteq y} g (y) \ times (-1) ^ {| y | - | x |} $

Can be found, where the capacity factor repellent only size-related, it directly transfers the distinction is not correct, it does not mean that it can be directly derived.

So now the inclusion-exclusion factor has been, the problem is only solved the g.

Now that you have enumerated the last, remaining unknown is the pos. So we also enumerate it.

Consider the total number of options:

First, we consider handpicked, elected on a pos position in all of the last. The answer take a [last]

Then we consider the type No. 1 request on those balls behind the POS, which provided a total of t, then the number of programs in any order thereof is (t + a [last] -1) !.

The reason for minus one, because you have identified the last of which put on pos.

While the back position pos th a total of m-pos, in these positions where you pick t + a [last] -1 to arrange such a ball, which is a number of combinations.

Then there are the rest of the balls (mta [last]) months. This number is arbitrary factorial arrangement scheme.

But there are two "in any order." In fact, not arbitrarily, because you ask for the ball to be No. 1 at the top, so even divided by $ \ prod \ limits_ {i \ neq last} a_i $

Take it all, this is the total number of programs.

It can be found, and there is only a pos-related, then it is proposed to separate the summation, for each of the last pre-calculated out again.

And then only with the relevant t. You have to know that it has several options, the ball just Couchu t several balls.

This is a classic knapsack problem, which is the last note to be mandatory. Calculated the total number of such programs, and then also the inclusion-exclusion?

You do not need. Because we find that the positive and negative coefficient of inclusion and exclusion related only to the number of elements, while the number of elements is exactly the number of items backpack.

+ = Total conversion so long as when the backpack is transferred - =, which automatically take on the coefficient -1. (Each of a plurality of elements, the number of opposite tolerance factor of repellent)

Then gone.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define int long long
 4 int fac[1005],m,n,inv[1005],a[1005],cnt,t[55],v[55],mx,dp[1005],C[1005][1005],INV=1,ans,f[10005];
 5 #define mod 1000000007
 6 main(){
 7     scanf("%lld",&n);fac[0]=fac[1]=inv[1]=dp[0]=1;
 8     for(int i=1;i<=n;++i)scanf("%lld",&a[i]),m+=a[i],INV=INV*a[i]%mod;
 9     for(int i=2;i<=m;++i)fac[i]=fac[i-1]*i%mod,inv[i]=mod-mod/i*inv[mod%i]%mod;
10     for(int i=0;i<=m;++i)C[i][0]=1;
11     for(int i=1;i<=m;++i)for(int j=1;j<=i;++j)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
12     for(int i=1;i<=m;++i)for(int j=i;j<=m;++j)f[i]=(f[i]+C[j-1][i-1])%mod;
13     for(int lst=1,tans;tans=a[lst],lst<=n;++lst){
14         for(int i=1;i<=m;++i)dp[i]=0;
15         for(int i=1;i<=n;++i)if(i!=lst)tans=tans*inv[a[i]]%mod;
16         for(int i=1;i<=n;++i)if(i!=lst)for(int j=m;~j;--j)dp[j+a[i]]=(dp[j+a[i]]-dp[j]+mod)%mod;
17         for(int t=0;t<=m;++t)ans=(ans+dp[t]*fac[t+a[lst]-1]%mod*fac[m-t-a[lst]]%mod*f[t+a[lst]]%mod*tans)%mod;
18     }cout<<ans<<endl;
19 }
View Code

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/12063627.html