[九省联考2018]一双木棋chess——搜索+哈希
2024-09-30 11:16:04
题目:bzoj5248 https://www.lydsy.com/JudgeOnline/problem.php?id=5248
洛谷P4363 https://www.luogu.org/problemnew/show/P4363
终于A了(虽然得开O2才能过)!
其实就是暴搜,用一个 n+1 进制数表示状态,进行最优策略转移即可;
注意 cnt[] 如果开成全局变量就不能每次翻译那个 n+1 进制数,否则会影响其它层的搜索;
(还有一种神奇的状态压缩是有几个用了 k 个1的列,就在第 k 个0后面加几个1……)
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
map<ll,ll>mp;
map<ll,bool>vis;
int n,m,s[][][],inf=1e9,cnt[];
ll pw(int a,int b)
{
ll ret=;
while(b){if(b&)ret*=a;a*=a;b>>=;}
return ret;
}
ll dfs(ll x,bool f)
{
if(vis[x])return mp[x];
vis[x]=;mp[x]=-inf;ll tx=x;
// for(int i=m;i;i--)cnt[i]=tx%(n+1),tx/=(n+1);
if(cnt[m]==n)return mp[x]=;
for(int i=;i<=m;i++)
{
if(cnt[i]==n||(i>&&cnt[i-]<=cnt[i]))continue;
cnt[i]++;
ll y=x+pw(n+,m-i);
mp[x]=max(mp[x],s[f][cnt[i]][i]-dfs(y,!f));
cnt[i]--;
}
return mp[x];
}
int main()
{
scanf("%d%d",&n,&m);
for(int k=;k<=;k++)
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&s[k][i][j]);
printf("%lld",dfs(,));
}
最新文章
- 大熊君JavaScript插件化开发------(实战篇之DXJ UI ------ ItemSelector)
- 微信网页授权snsapi_base、snsapi_userinfo的问题
- matlab linux 安装
- iOS resign code with App Store profile and post to AppStore
- [转]Flash Socket通信的安全策略
- S2--《优化MySchool数据库设计》总结
- 错误记录--The import XXX cannot be resolved
- Ubuntu下安装可视化SVN客户端Rabbitvcs
- 4月13日学习笔记——jQuery工具函数
- .Net IE10 _doPostBack 未定义
- 开始学习HTML5
- MSChart实例
- 从花式swap引出的pointer aliasing问题
- EF异常探究(An entity object cannot be referenced by multiple instances of IEntityChangeTracker.)
- clique
- Generator和Async
- npm WARN enoent ENOENT: no such file or directory, open &#39;C:\Users\package.json&#39;
- 怎样下载youtube的字幕
- python如何去掉字符串‘\xa0’
- 获取地图文档(*.mxd)中比例尺问题