bzoj

luogu

sol

首先,要保证一个格子的左边和上方都放满了棋子,就需要这个点的左上方那个矩形都放满了棋子。

这样放棋子状态就会是一个自左下至右上的轮廓线。

状态数?\(C_{20}^{10}\)。相当于是从左下角走到右上角一共要走\(20\)步,在其中选出\(10\)向上走其余的向右走。

也可以打个表看一看。。。

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,a[20],tot;
void dfs(int u)
{
if (u==n+1) {++tot;return;}
for (int i=a[u-1];i<=m;++i)
a[u]=i,dfs(u+1);
}
int main()
{
n=10;m=10;dfs(1);
printf("%d\n",tot);
return 0;
}

这里打表打的就是\(10\)个\([0,10]\)整数单调不降的方案数。

运行结果:

184756

既然状态数这么少就直接\(hash\)一下然后\(map\)存啊。

把既然是\([0,10]\)的整数就把它压成一个\(11\)进制的数,显然并不会爆long long。

可以直接\(dp\)。判断一下当前状态是先手还是后手进行操作,如果是先手操作就是从所有后继状态的\(dp\)值中取\(\max\),否则就是取\(\min\)。

code

#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long
int gi()
{
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
const int N = 20;
const int inf = 2e9;
int n,m,A[N][N],B[N][N],a[N];
map<ll,int>M;
ll hash()
{
ll res=0;
for (int i=1;i<=n;++i) res=res*11+a[i];
return res;
}
void unpack(ll zt)
{
for (int i=n;i;--i) a[i]=zt%11,zt/=11;
}
int dfs(ll zt)
{
if (M.find(zt)!=M.end()) return M[zt];
unpack(zt);int t=0,res;
for (int i=1;i<=n;++i) t^=a[i]&1;
res=t?inf:-inf;
for (int i=1;i<=n;++i)
if (a[i-1]>a[i])
{
++a[i];
ll nxt=hash();
if (t) res=min(res,dfs(nxt)-B[i][a[i]]);
else res=max(res,dfs(nxt)+A[i][a[i]]);
--a[i];
}
return M[zt]=res;
}
int main()
{
n=gi();m=gi();a[0]=m;
for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) A[i][j]=gi();
for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) B[i][j]=gi();
for (int i=1;i<=n;++i) a[i]=m;M[hash()]=0;
printf("%d\n",dfs(0));return 0;
}

最新文章

  1. xcode8.0升级之后公司项目遇到的问题
  2. Linux环境数据备份Python脚本
  3. AngularJs angular.element
  4. Convert between cv::Mat and QImage 两种图片类转换
  5. oracle参数与启停
  6. sql中实现split()功能
  7. 430的启动,I/O中断
  8. hadoop中Combiner使用中需要注意的地方
  9. 【Linux】鸟哥的Linux私房菜基础学习篇整理(十)
  10. Delphi 函数指针(函数可以当参数)
  11. poj 2153 Rank List(查找,Map)
  12. 《重新定义公司 - Google 是如何运营的》重点摘录
  13. 1.6分布式通讯协议-WebService
  14. windows下安装php reids扩展
  15. 微信小程序textarea组件在fixed定位中随页面滚动
  16. Hive入门学习
  17. js 标准二维数组变一维数组的方法
  18. ngx_lua_API 指令详解(六)ngx.thread.spawn、ngx.thread.wait、ngx.thread.kill介绍
  19. Densenet 相关
  20. freemarker 判断写法

热门文章

  1. ZOJ 3961 Let's Chat 【水】
  2. swift的值类型和引用类型
  3. Python学习进程(14)异常处理
  4. $《第一行代码:Android》读书笔记——第6章 数据持久化
  5. pdoModel封装
  6. Linux的Cache Memory(缓存内存)机制
  7. Android : 反射机制获取或设置系统属性(SystemProperties)【转】
  8. codeforces 439D 思维
  9. sql server update时,是行锁还是表锁
  10. Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;company&#39; in &#39;class java.lang.String&#39;