BZOJ5248: [Nine Provinces Joint Exam 2018] A Pair of Wooden Chess - Problem Solving

https://www.lydsy.com/JudgeOnline/problem.php?id=5248

https://www.luogu.org/problemnew/show/P4363#sub

Feifei and Niuniu play chess on a chessboard with n rows and m columns. Feifei plays black first, and Niuniu plays white. At the beginning of the chess game, there are no pieces on the board, and the two take turns placing pieces on the grid until the board is filled. The rule of moving stones is: a square can be moved if and only if there are no stones in this square and there are stones in all squares to the left and above of this square.
Two non-negative integers are written on each grid of the chessboard, and the two integers on the grid on the jth column from left to right in the i-th row from top to bottom are denoted as Aij and Bij. After the game is over, Feifei and Niuniu will calculate their own scores: Feifei's score is the sum of Aij on all black squares, and Niuniu's score is the sum of Bij on all white squares.
Feifei and Niuniu both hope that the result obtained by subtracting the opponent's score from their own score is the greatest. Now they want to know, on a given chessboard, what would be the final outcome if both players had an optimal strategy and knew that the other would have an optimal strategy

The shape of each added piece is always a trapezoid-like shape, and there may be fewer states, not to mention that n and m are only 10, so I think of the shape pressure dp.

Since the chessboard model can think of the plug dp, the contour line is the boundary of the obvious chess piece.

So the downward plug is 0, and the right plug is 1. Obviously, the state is only 2^(n+m), and the memory search can be done.

 

After the explanation is over, it's time to complain:

woc my ** is out of my mind, did I write a confrontation search during the exam? ? ? It may not be easy to think about not writing about the plug dp, but I have learned about the plug dp anyway.

After I finished (after knowing the solution), I forgot to write a memoization search and it was an A...

Maybe my brain isn't born for OI.

#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;
const int N=11;
const int INF=1e9;
inline int read(){
    int X=0,w=0;char ch=0;
    while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
    while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
int n,m,a[N][N],b[N][N],f[1<<(N*2)][2];
int dp(int s,int id){
    if(f[s][id]!=INF)return f[s][id];
    int c[N<<1]={0};
    int l=-1,tmp=s;
    while(tmp){int t=tmp-tmp/2*2;c[++l]=t;tmp>>=1;}
    l=n+m-1;
    int ans=id?INF:-INF;
    int x=0,y=0;
    for(int i=0;i<=l;i++){
        if(!c[i])y++;
        else x++;
        if(i&&c[i-1]&&(!c[i])){
            tmp=s-(1<<i>>1)+(1<<i);
            if(!id)ans=max(ans,dp(tmp,id^1)+a[n-x+1][y]);
            else ans=min(ans,dp(tmp,id^1)-b[n-x+1][y]);
        }
    }
    return f[s][id]=(ans==INF||ans==-INF)? 0 : years;
}
int main(){
    n=read(),m=read();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            a[i][j]=read();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            b[i][j]=read();
    for(int i=0;i<(1<<(n+m));i++)
        f[i][0]=f[i][1]=INF;
    int res=0;
    for(int i=0;i<n;i++)res+=1<<i;
    printf("%d\n",dp(res,0));            
    return 0;
}

+++++++++++++++++++++++++++++++++++++++++++

+ Author of this article: luyouqi233. +

+Welcome to my blog: http://www.cnblogs.com/luyouqi233/  +

+++++++++++++++++++++++++++++++++++++++++++

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324384530&siteId=291194637