题目链接

题目大意

要你求有多少个满足题目条件的矩阵mod 1e9+7

\(a[1][1]=2018\;\;a[i][j]为a[i-1][j]和a[i][j-1]的因子\)

题目思路

dp也就图一乐,真正比赛还得看打表

一直在想dp,其实却是打表找规律

只能说看到答案固定的题目就应该要去想打表

然后发现规律

打表代码

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define fi first
#define se second
#define debug printf(" I am here\n");
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e3+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-10;
int n,m,a[maxn][maxn],cnt;
int num[]={0,1,2,1009,2018};
void dfs(int x,int y,int n,int m){
if(x>n||y>m) return ;
if(x==1&&y==1){
a[1][1]=2018;
if(x==n&&y==m){
cnt++;
}else if(y==m){
dfs(x+1,1,n,m);
}else{
dfs(x,y+1,n,m);
}
}else if(x==1){
for(int i=1;i<=4;i++){
if(a[x][y-1]%num[i]!=0) continue;
a[x][y]=num[i];
if(x==n&&y==m){
cnt++;
}else if(y==m){
dfs(x+1,1,n,m);
}else{
dfs(x,y+1,n,m);
}
}
}else if(y==1){
for(int i=1;i<=4;i++){
if(a[x-1][y]%num[i]!=0) continue;
a[x][y]=num[i];
if(x==n&&y==m){
cnt++;
}else if(y==m){
dfs(x+1,1,n,m);
}else{
dfs(x,y+1,n,m);
}
}
}else{
for(int i=1;i<=4;i++){
if(a[x-1][y]%num[i]!=0) continue;
if(a[x][y-1]%num[i]!=0) continue;
a[x][y]=num[i];
if(x==n&&y==m){
cnt++;
}else if(y==m){
dfs(x+1,1,n,m);
}else{
dfs(x,y+1,n,m);
}
}
}
}
signed main(){
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cnt=0;
dfs(1,1,i,j);
printf("%d ",cnt);
}
cout<<endl;
}
return 0;
}

代码

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define fi first
#define se second
#define debug printf(" I am here\n");
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=2e3+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-10;
int n,m;
int dp[maxn][maxn];
signed main(){
dp[1][1]=1;
for(int i=1;i<=2000;i++){
for(int j=1;j<=2000;j++){
if(i==1&&j==1) continue;
dp[i][j]=(dp[i-1][j]+dp[i][j-1]+1)%mod;
}
}
while(scanf("%d%d",&n,&m)!=-1){
printf("%d\n",1ll*dp[n][m]*dp[n][m]%mod);
}
return 0;
}

2018-div-matrix 题解(打表)的更多相关文章

  1. 喵哈哈村的魔法考试 Round #1 (Div.2) 题解

    喵哈哈村的魔法考试 Round #1 (Div.2) 题解 特别感谢出题人,qscqesze. 也特别感谢测题人Xiper和CS_LYJ1997. 没有他们的付出,就不会有这场比赛. A 喵哈哈村的魔 ...

  2. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  3. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  4. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  5. 喵哈哈村的魔法考试 Round #2 (Div.2) 题解

    喵哈哈村的魔法考试 Round #2 (Div.2) 题解 A.喵哈哈村的战争 题解: 这道题就是for一遍,统计每个村子的战斗力的和,然后统计哪个村子的战斗力和大一点就好了. 唯一的坑点,就是这道题 ...

  6. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  7. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  8. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  9. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  10. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

随机推荐

  1. webpack 单独打包指定JS文件

    背景 最近接到一个需求,因为不确定打出的前端包所访问的后端IP,需要对项目中IP配置文件单独拿出来,方便运维部署的时候对IP做修改.因此,需要用webpack单独打包指定文件. CommonsChun ...

  2. eclipse之SSH配置spring【二】

    第一篇中配置struts完成(http://www.cnblogs.com/dev2007/p/6475074.html),在此基础上,继续配置spring. web.xml中增加listener,依 ...

  3. Yum 命令出现[Errno 256] No more mirrors to try错误的解决方式

    今天我在虚拟机上安装 NetCore 的 SDK 的时候,出现错误,执行命令:"yum install dotnet-sdk-3.1",最后安装失败,很多安装包没有找到镜像.解决方 ...

  4. STM32入门系列-GPIO概念介绍

    GPIO(general purpose intput output)是通用输入输出端口的简称,可以通过软件来控制其输入和输出.STM32 芯片的 GPIO 引脚与外部设备连接起来,从而实现与外部通讯 ...

  5. Day13 CSS样式

    1. css 选择器 1.1 css三种引入方法 <!DOCTYPE HTML> <html> <head> <meta charset="utf- ...

  6. Java的浅拷贝与深拷贝

    Java的浅拷贝与深拷贝 Java中,所有的类都继承Object,Object中有clone方法,它被声明为了 protected ,所以我们但是如果要使用该方法就得重写且声明为public,必须在要 ...

  7. 2.1获取Git仓库-2.2记录每次更新到仓库

    2.1 获取 Git 仓库 获取 Git 仓库通常有两种方式 将尚未进行版本控制的本地目录转换为 Git 仓库: 从其它服务器 克隆 一个已存在的 Git 仓库. 在已存在目录中初始化仓库 首先进入该 ...

  8. JVM 整体回顾(一)

    JAVA虚拟机整体的回顾,为提纲类型 JAVA虚拟机是装在操作系统之上的一个应用软件[平台性质],作用是:将class格式的字节码编译成可执行的机器码.从而,class格式和物理机无关.也就是所谓的j ...

  9. 依赖注入DI(IOC)容器快速入门

    1.什么是IOC IOC是一种设计模式,全程控制翻转或叫依赖注入.更详细介绍见http://martinfowler.com/articles/injection.html 2.为什么用IOC 我们通 ...

  10. 五分钟看懂抓包神技:DPDK

    我是一个网络监控软件,我被开发出来的使命就是监控网络中进进出出的所有通信流量. 一直以来,我的工作都非常的出色,但是随着我监控的网络越来越庞大,网络中的通信流量也变得越来越多,我开始有些忙不过来了,逐 ...