题目链接

题目大意

要你求有多少个满足题目条件的矩阵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. Libevent库基础(2)

    带缓冲区的事件 bufferevent #include <event2/bufferevent.h> read/write 两个缓冲. 借助 队列. 创建.销毁bufferevent: ...

  2. Spring入门-----------------属性注入和对象注入

    属性注入即通过setter方法注入bean的属性或依赖对象. 属性注入使用<property>元素,使用name属性指定bean的属性的名称,value属性或<value>子节 ...

  3. JAVA概述-JAVA入门基础

    一.JAVA的历史 Java是1995年由Sun公司(现Oracle公司)推出的一门面向对象的高级编程语言.这门编程语言的Logo就像是一杯刚刚煮好的咖啡. Java最初期的开发是在1991年,最初的 ...

  4. CF618F Double Knapsack

    题意简化 给定两个大小为 n 的集合A,B,要求在每个集合中选出一个子集,使得两个选出来的子集元素和相等 元素范围在 1~n ,n<=1e5 题目连接 题解 考虑前缀和 令A集合的前缀和为SA, ...

  5. 关于Java中泛型、反射和注解的扫盲篇

    泛型 泛型概念   泛型是在JDK1.5之后引入的,旨在让我们写出更加通用化,更加灵活的代码.通用化的手段在于让数据类型变得参数化,定义泛型时,对应的数据类型是不确定的,泛型方法被调用时,会指定具体类 ...

  6. jackson、fastjson、kryo、protostuff等序列化工具性能对比

    简介 实际项目中,我们经常需要使用序列化工具来存储和传输对象.目前用得比较多的序列化工具有:jackson.fastjson.kryo.protostuff.fst 等,本文将简单对比这几款工具序列化 ...

  7. 最简单的基于FFmpeg的直播系统开发移动端例子:IOS 视频解码器

    本文记录IOS平台下基于FFmpeg的视频解码器.该示例C语言的源代码来自于<最简单的基于FFMPEG+SDL的视频播放器>.相关的概念就不再重复记录了. 源代码 项目的目录结构如图所示. ...

  8. 阿里巴巴开发手册强制使用SLF4J作为门面担当的秘密,我搞清楚了

    之前已经详细.全面地介绍了 Log4j,相信小伙伴们已经完全掌握了.那我在读嵩山版的阿里巴巴开发手册(没有的小伙伴,记着找我要)的时候,就发现了一条「强制」性质的日志规约: 应用中不可以直接使用日志系 ...

  9. 利用远程桌面管理winserver集群

    在适用mstsc连接winserver服务器的场景下(别问为什么不VNC),可以利用rdp文件等方式减轻连接的操作负担 利用.rdp文件免密登录 rdp文件本质上是一个mstsc的选择,或者不如说ms ...

  10. []Spring创建Bean的过程

    1. beans包提供了以编程方式管理和操作bean的基本功能,而context包增加了ApplicationContext,它以一种更加面向框架的方式增强了BeanFactory的功能. 2. co ...