代码

#include<cstdio>
using namespace std; const int N = 20 , mod = 1e9 + 7 , K = 10;
int f[N + 5][N + 5] , map[N + 5][N + 5] , vis[K + 5] , n , m , k; inline int dfs(int x , int y)
{
if (y == m + 1) return dfs(x + 1 , 1);
if (x == n + 1) return 1; f[x][y] = f[x - 1][y] | f[x][y - 1];
int num = 0 , sum = 0 , res = 0 , bz = 0; for(register int i = 1; i <= k; i++)
if (!(f[x][y] & (1 << i - 1))) num++;
if (num < n + m - x - y + 1) return 0; if (!map[x][y])
{
for(register int i = 1; i <= k; i++)
if (!(f[x][y] & (1 << i - 1)))
{
if (!vis[i])
{
if (bz == 1)
{
res = (res + sum) % mod;
continue;
}
else
{
bz = 1;
vis[i]++;
f[x][y] |= 1 << i - 1;
sum = dfs(x , y + 1);
res = (res + sum) % mod;
f[x][y] ^= 1 << i - 1;
vis[i]--;
}
continue;
}
vis[i]++;
f[x][y] |= 1 << i - 1;
res = (res + dfs(x , y + 1)) % mod;
f[x][y] ^= 1 << i - 1;
vis[i]--;
}
}
else if (!(f[x][y] & (1 << map[x][y] - 1)))
{
f[x][y] |= 1 << map[x][y] - 1;
res = (res + dfs(x , y + 1)) % mod;
f[x][y] ^= 1 << map[x][y] - 1;
}
return res;
} int main()
{
scanf("%d%d%d" , &n , &m , &k);
if (n + m - 1 > k)
{
printf("0");
return 0;
}
for(register int i = 1; i <= n; i++)
for(register int j = 1; j <= m; j++)
{
scanf("%d" , &map[i][j]);
vis[map[i][j]]++;
}
printf("%d" , dfs(1 , 1));
}

最新文章

  1. SQL Server 系列文章快速导航(SWF版)
  2. codeforces D. Design Tutorial: Inverse the Problem
  3. 10.23lamp环境
  4. 【BZOJ】2329: [HNOI2011]括号修复(splay+特殊的技巧)
  5. [转](多实例)mysql-mmm集群
  6. HTMLEncode httpencode UTF8Encode
  7. poj1338
  8. chrony时间同步 服务端 客户端 安装配置
  9. windows下cmd中命令操作
  10. TF:TF下CNN实现mnist数据集预测 96%采用placeholder用法+2层C及其max_pool法+隐藏层dropout法+输出层softmax法+目标函数cross_entropy法+AdamOptimizer算法
  11. thread run 和 start 的区别
  12. yum 安装mysql数据库
  13. css笔记 - transform学习笔记(二)
  14. Android解析WindowManager(三)Window的添加过程
  15. 【Cf Edu #47 G】Allowed Letters
  16. entityframework导航属性筛选
  17. 1z0-052 q209_6
  18. 创建 cachingConfiguration 的配置节处理程序时出错: 未能加载文件或
  19. Android studio 和 Eclipse快捷键对比
  20. 217. Contains Duplicate数组重复元素 123

热门文章

  1. uboot引导应用程序
  2. xml中出现&lt; &gt;&amp;等特殊字符如何存储
  3. 编译器优化丨Cache优化
  4. 【数据库】Postgresql、PG的分区操作:创建、删除指定分区,非分区表转分区表
  5. Spring01:概述、工厂模式解耦、Spring中的IOC
  6. python多线程批量操作交换机
  7. Kubernetes单机创建MySQL+Tomcat演示程序:《Kubernetes权威指南》第一章demo报错踩坑
  8. ModuleNotFoundError: No module named &#39;MySQLdb&#39;
  9. 解决MVVMLight导航VM不重置问题
  10. [OpenCV实战]23 使用OpenCV获取高动态范围成像HDR