2019.9.27 csp-s simulation test 53 to reflect summary

This way there is actually named follow-up? !

Why not continuous named? !

 

T1 thought for a long time, do come out, the resulting array to open a small range [actually] did not pay attention. T2 jump directly to the desired probability, then turned back to find myself writing it wrong expectations of the whole meaning of [what]. T3 wrong to think of the results of the construction of the track a mistake greedy.

About T2 破罐子破摔 output k actually lied to the twentieth of it ......

 

T1u:

I want to start a variety of bias, which is the value of maintaining odd or even number, which values ​​change considerations affect every operation ... These are all run out.

After about a century long, suddenly thinking process can not optimize the operation of direct ah, then violence research, finally began to think of the difference.

Nq then felt the complexity of the trouble, began to be messing around difference. Finally after so long a century, also found that the differential array can be passed transferred ......

Two centuries later, the then no.

#include<iostream>
#include<cstdio>
using namespace std;
int n,q;
long long ans,f[2010][2010],H[2010][2010],L[2010][2010],sum;
int main()
{
    scanf("%d%d",&n,&q);
    if(!q){
        printf("0\n");
        return 0;
    }
    else if(n<=300){
        for(int i=1,r,c,l,s;i<=q;i++){
            scanf("%d%d%d%d",&r,&c,&l,&s);
            for(int j=r;j<r+l;j++){
                for(int k=c;k<=j-r+c;k++){
                    f[j][k]+=s;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                ans^=f[i][j];
            }
        }
        printf("%lld\n",ans);
        return 0;
    }
    else if(q<=2000){
        for(int i=1,r,c,l,s;i<=q;i++){
            scanf("%d%d%d%d",&r,&c,&l,&s);
            for(int j=r;j<r+l;j++){
                H[j][c]+=s;
                H[j][j-r+c+1]-=s;
            }
        }
        for(int i=1;i<=n;i++){
            sum=0;
            for(int j=1;j<=n;j++){
                sum+=H[i][j];
                ans^=sum; 
            }
        }
        printf("%lld\n",ans);
        return 0;
    }
    else{
        for(int i=1,r,c,l,s;i<=q;i++){
            scanf("%d%d%d%d",&r,&c,&l,&s);
            H[r][c]+=s;
            L[r][c+1]-=s;
            H[r+l][c]-=s;
            L[r+l][c+l+1]+=s;
        }
        for(int i=1;i<=n;i++){
            sum=0;
            for(int j=1;j<=n;j++){
                H[i][j]+=H[i-1][j];
                L[i][j]+=L[i-1][j-1]; 
                sum+=H[i][j]+L[i][j];
                ans^=sum; 
            }
        }
        printf("%lld\n",ans);
        return 0;
    }
}
View Code

 

 

T2v:

Whole child made a mistake expect this stuff, hard to describe.

The title of the optimal strategy, referring to the contribution in the election with a certain probability to a certain position, the choice to take the ball in front of or behind the ball take one decision generated a total on the ball is not white ball contribution, whichever is greater.

So dfs, which enumerate the election to the position, the cumulative contribution, divided by the number of species to the optional position, we would expect this state.

Because the search to the state will be a lot of duplication, consider memory search. But the number that represents a certain state can be large, the array subscript can not be expressed. So to get out of the array representation, to keep an array. Other larger map solve a map.

Status of different lengths may exist on the same value, for example 010 and 0010. The solution is then in front of this a marked length marker is a 1, for example 010> 1010,0010-> 10010, this indicates a different state.

#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int n,k;
char s[31];
long long fir;
double ans,num[(1<<25)];
map<long long,double>m;
double dfs(long long x,int k,int lon){
    if(!k)return 0;
    if(lon<=25&&num[x]!=-1.0)return num[x];
    else if(m.find(x)!=m.end())return m[x];
    double f=0,f1=0,val1,val2;
    long long x1,x2;
    for(int i=1;i<=lon/2;i++){
        val1=(x>>(lon-i-1))&1,val2=(x>>(i-1))&1;
        f1=0;
        x1=(x>>1)&(~((1<<(lon-i-1))-1))|(x&((1<<(lon-i-1))-1));
        x2=(x>>1)&(~((1<<(i-1))-1))|(x&((1<<(i-1))-1));
        f1=dfs(x1,k-1,lon-1)+val1;
        f1=max(f1,dfs(x2,k-1,lon-1)+val2);
        f+=f1*(i==lon-i?1.0:2.0);
    }
    f/=(double)(lon-1);
    if(lon<=25)num[x]=f;
    else m[x]=f;
    return f;
}
int main(){
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    for(int i=0;i<=(1<<25);i++)num[i]=-1.0;
    fir=1;
    for(int i=1;i<=n;i++){
        fir=(fir<<1)+(s[i]=='W');
    }
    ans=dfs(fir,k,n+1);
    printf("%.10lf",ans);
    return 0;
}
View Code

 

 

T3w:

Error Greedy: forced by a path that each node of the child node if even-numbered pass up on its own optimal solution, this odd-numbered side of the target to see node 2 is not even out, and then passed up no brain.

Error of the obvious ...... it is possible to forcibly passed up this disrupts parent may have been a combination of complete self-pairing, add a path to the parent node, then had to wear again, but also increases the length ...... not as good as in the current node their.

Correct answer is tree DP. Finally, the total number of paths found in the path is an odd whole tree points degrees / 2. For each point, one edge to record or transmit it does not pass when dp [x] [1], dp [x] [0], comprises a minimum number of points odd degree subtree and a minimum on the basis of the total path length .

A subtree transferred. Tuple w1 set up two sub-trees are used to count the optimal answer, w2. w1 is the meaning of sub-trees have to pass one edge, w2 is not to let them pass twenty-two resolved. For each of them subtree y, w1 = min (w2 + dp [y] [1], w1 + dp [y] [0]), w2 = min (w1 + dp [y] [1], w2 + dp [y ] [0]). Compare the size when they are first Compare odd degree points c1, then compare path length c2.

Dpx then it calculated based on the current top of this edge node and target states. Obviously if you have one side is the target state, then do not go necessarily always better. If this edge is already the target state, let dp [x] [1] = inf. W1 so that the c1 ++, w2 unchanged, if the edge represents the more finishing pass up as a singularity point degree, or not pass up on the same side, and dp [x] [0] w1 and w2 are selected in better . If this edge is not a target state, let dp [x] [0] = inf. w1.c2 ++. w2.c1 ++, w2.c2 ++, this represents the beginning of a new node as the odd degree nodes increases. Still let dp [x] [1] to select better in w1 and w2 in. If the target state of this edge is 2, then two cases are non-partial inf do it again.

#include<iostream>
#include<cstdio>
using namespace std;
const int inf=214748364;
int f[100010][2],opt[100010],goal[100010];
struct node{
    int c1,c2;
}dp[100010][2],tool;
int n,tot,ver[200010],head[100010],edge[200010],edge1[200010],Next[200010];
void add(int x,int y,int z,int w){
    ver[++tot]=y;
    Next[tot]=head[x];
    head[x]=tot;
    edge[tot]=z;
    edge1[tot]=w;
}
node work(node a,node b,node c,node d){
    node e;
    if(a.c1+b.c1<c.c1+d.c1){
        e.c1=a.c1+b.c1;
        e.c2=a.c2+b.c2;
    }
    else if(a.c1+b.c1==c.c1+d.c1){
        if(a.c2+b.c2<c.c2+d.c2){
            e.c1=a.c1+b.c1;
            e.c2=a.c2+b.c2;
        }
        else{
            e.c1=c.c1+d.c1;
            e.c2=c.c2+d.c2;
        }
    }
    else{
        e.c1=c.c1+d.c1;
        e.c2=c.c2+d.c2;
    }
    return e;
}
void dfs(int x,int fa){
    node w1,w2;
    w1.c1=w1.c2=inf;
    w2.c1=w2.c2=0;
    for(int i=head[x];i;i=Next[i]){
        int y=ver[i];
        if(y==fa)continue;
        opt[y]=edge[i];
        goal[y]=edge1[i];
        dfs(y,x);
        node w11=w1;
        w1=work(dp[y][0],w1,dp[y][1],w2);
        w2=work(dp[y][1],w11,dp[y][0],w2);
    }
    if(goal[x]==2){
        w2.c1++;
        w1.c2++;
        w2.c2++;
        dp[x][1]=work(w1,tool,w2,tool);
        w2.c1--;
        w1.c2--;
        w2.c2--;
        w1.c1++;
        dp[x][0]=work(w1,tool,w2,tool);
    }
    else{
        if(opt[x]!=goal[x]){
            dp[x][0].c1=inf,dp[x][0].c2=inf;
            w2.c1++;
            w1.c2++;
            w2.c2++;
            dp[x][1]=work(w1,tool,w2,tool);
        }
        else{
            dp[x][1].c1=inf,dp[x][1].c2=inf;
            w1.c1++;
            dp[x][0]=work(w1,tool,w2,tool);
        }
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1,x,y,z,w;i<n;i++){
        scanf("%d%d%d%d",&x,&y,&z,&w);
        add(x,y,z,w),add(y,x,z,w);
    } 
    dfs(1,0);
    printf("%d %d\n",dp[1][0].c1/2,dp[1][0].c2);
    return 0;
}
View Code

 

 

It was delayed until the moment before the finish.

Happy Mother's birthday wish our motherland.

Guess you like

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