Distinct Paths
2024-10-21 03:14:47
代码
#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));
}
最新文章
- SQL Server 系列文章快速导航(SWF版)
- codeforces D. Design Tutorial: Inverse the Problem
- 10.23lamp环境
- 【BZOJ】2329: [HNOI2011]括号修复(splay+特殊的技巧)
- [转](多实例)mysql-mmm集群
- HTMLEncode httpencode UTF8Encode
- poj1338
- chrony时间同步 服务端 客户端 安装配置
- windows下cmd中命令操作
- TF:TF下CNN实现mnist数据集预测 96%采用placeholder用法+2层C及其max_pool法+隐藏层dropout法+输出层softmax法+目标函数cross_entropy法+AdamOptimizer算法
- thread run 和 start 的区别
- yum 安装mysql数据库
- css笔记 - transform学习笔记(二)
- Android解析WindowManager(三)Window的添加过程
- 【Cf Edu #47 G】Allowed Letters
- entityframework导航属性筛选
- 1z0-052 q209_6
- 创建 cachingConfiguration 的配置节处理程序时出错: 未能加载文件或
- Android studio 和 Eclipse快捷键对比
- 217. Contains Duplicate数组重复元素 123
热门文章
- uboot引导应用程序
- xml中出现<; >;&;等特殊字符如何存储
- 编译器优化丨Cache优化
- 【数据库】Postgresql、PG的分区操作:创建、删除指定分区,非分区表转分区表
- Spring01:概述、工厂模式解耦、Spring中的IOC
- python多线程批量操作交换机
- Kubernetes单机创建MySQL+Tomcat演示程序:《Kubernetes权威指南》第一章demo报错踩坑
- ModuleNotFoundError: No module named &#39;MySQLdb&#39;
- 解决MVVMLight导航VM不重置问题
- [OpenCV实战]23 使用OpenCV获取高动态范围成像HDR