当前位置: 首页 > news >正文

Dynamic Programming【DP】2

问题 F: Grid Paths

题目描述

Consider an n * n grid whose squares may have traps. It is not allowed to move to a square with a trap.
Your task is to calculate the number of paths from the upper-left square to the lower-right square. You can only move right or down.

输入

The first input line has an integer n: the size of the grid.
After this, there are n lines that describe the grid. Each line has n characters: . denotes an empty cell, and * denotes a trap.
Constraints
1 ≤ n ≤ 1000

输出

Print the number of paths modulo 109+7.

样例输入

复制

4
....
.*..
...*
*...
样例输出

复制

3

代码

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1010;
const int mod=1e9+7;int n,k[1010][1010];
vector<vector<int>>dp(N,vector<int>(N,0));
char x;int main()
{cin>>n;for(int i=1;i<=n;++i){for(int j=1;j<=n;++j){cin>>x;if(x=='.')k[i][j]=1;else k[i][j]=0;}}if(k[1][1])dp[1][1]=1;for(int i=1;i<=n;++i){for(int j=1;j<=n;++j){if(k[i][j]){dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%mod;}}}cout<<dp[n][n];return 0;
}

http://www.dtcms.com/a/314735.html

相关文章:

  • RAG中的评估指标总结:BLEU、ROUGE、 MRR、MAP、nDCG、Precision@k、Recall@k 等
  • AR远程协作网页设计:虚实融合场景下的故障标注与操作指引界面
  • cf--思维训练
  • Git如何为多平台配置密钥和用户信息?
  • Git简易教程
  • PEAFOWL-IEEE-2025
  • Integer Types Range and varieties
  • 20250723-算法分析与设计之旅行商问题(Traveling Salesman Problem,TSP)
  • Antlr学习笔记 01、maven配置Antlr4插件案例Demo
  • golang的数组
  • SpringBoot-手动配置环境
  • VUE2 学习笔记17 路由
  • 一起学springAI系列一:流式返回
  • 嵌入式 - 数据结构:查找至双向链表
  • CUDA后端错误的根源与系统性解决方案
  • python文件操作:写入内容write
  • Linux 服务器性能监控、分析与优化全指南
  • Linux 安装与配置 MySQL 教程
  • 项目实战二:RPC
  • 自制简易SHELL
  • 数据结构:单向链表、双向链表
  • Java中给List<T> 对象集合去重
  • 深化中坦经贸合作 谱写东非璀璨新篇!东非商贸物流中心(EACLC)正式启航
  • Baumer工业相机堡盟工业相机如何通过YoloV8深度学习模型实现路口车辆速度的追踪识别(C#代码UI界面版)
  • 通过java将 word(.doc) 转 md
  • Java数组转换为逗号分隔字符串的方法
  • dbeaver导入数据及配置讲解
  • 通过 Flink 和 CDC 从 Oracle 数据库获取增量数据,并将这些增量数据同步到 MySQL 数据库中
  • Go 与 Python 爬虫代码实操对比
  • # 自动定时运行Python爬虫脚本教程(Windows任务计划程序)