1. 程式人生 > >LOJ#2471「九省聯考 2018」一雙木棋 MinMax博弈+記搜

LOJ#2471「九省聯考 2018」一雙木棋 MinMax博弈+記搜

題解 base print ... 感覺 max ace read 博弈

題面

戳這裏

題解

因為每行取的數的個數是單調不增的,感覺狀態數不會很多?

怒而記搜,結果過了...

#include<bits/stdc++.h>
#define For(i,x,y) for (int i=(x);i<=(y);i++)
#define Dow(i,x,y) for (int i=(x);i>=(y);i--)
#define cross(i,k) for (int i=first[k];i;i=last[i])
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
    ll x=0;int ch=getchar(),f=1;
    while (!isdigit(ch)&&(ch!=‘-‘)&&(ch!=EOF)) ch=getchar();
    if (ch==‘-‘){f=-1;ch=getchar();}
    while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-‘0‘;ch=getchar();}
    return x*f;
}
const int N = 15;
int n,m,a[N][N],b[N][N];
map<ull,int>Map;
int now[N];
const ull base = 233;
inline ull Get(){
    ull ans=0;
    For(i,1,n) ans=ans*base+now[i];
    return ans; 
}
inline int dfs(int x){
    ull hsh=Get();
    if (Map.count(hsh)) return Map[hsh];
    int tmp=(!x)?-1e9:1e9;
    For(i,1,n) 
        if (now[i]+1<=now[i-1]){
            now[i]++;
            if (x>0) tmp=min(tmp,dfs(x^1)-b[i][now[i]]);
                else tmp=max(tmp,dfs(x^1)+a[i][now[i]]);
            now[i]--;
        }
    return Map[hsh]=tmp;
}
int main(){
     n=read(),m=read();
     For(i,1,n)
        For(j,1,m) a[i][j]=read();
     For(i,1,n)
        For(j,1,m) b[i][j]=read();
     For(i,1,n) now[i]=m;
     Map[Get()]=0,memset(now,0,sizeof now),now[0]=m;
     printf("%d",dfs(0));
}

LOJ#2471「九省聯考 2018」一雙木棋 MinMax博弈+記搜