2018-div-matrix 题解(打表)
题目链接
题目大意
要你求有多少个满足题目条件的矩阵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 题解(打表)的更多相关文章
- 喵哈哈村的魔法考试 Round #1 (Div.2) 题解
喵哈哈村的魔法考试 Round #1 (Div.2) 题解 特别感谢出题人,qscqesze. 也特别感谢测题人Xiper和CS_LYJ1997. 没有他们的付出,就不会有这场比赛. A 喵哈哈村的魔 ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- 喵哈哈村的魔法考试 Round #2 (Div.2) 题解
喵哈哈村的魔法考试 Round #2 (Div.2) 题解 A.喵哈哈村的战争 题解: 这道题就是for一遍,统计每个村子的战斗力的和,然后统计哪个村子的战斗力和大一点就好了. 唯一的坑点,就是这道题 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
随机推荐
- Luogu P6830 [IOI2020]Connecting Supertrees
题意 好复杂,我就不写了. 题解 口胡了一下,发现我居然会 IOI 的题? 首先发现有 \(3\) 一定不合法,因为连通块里面有一个环的话 \(p_{i,j}\) 最多为 \(2\),有两个环的话就存 ...
- yii中的andFilterWhere使用说明
当 WHERE 条件来自于用户的输入时,你通常需要忽略用户输入的空值. 例如,在一个可以通过用户名或者邮箱搜索的表单当中,用户名或者邮箱 输入框没有输入任何东西,这种情况下你想要忽略掉对应的搜索条件, ...
- Servlet学习笔记(二)
目录 Servlet学习笔记(二) Request对象 1.request和response对象: 2.request对象继承体系结构: 3.什么是HttpServletRequest ? 4.Htt ...
- CSP-S 2020全国开放赛前冲刺模拟训练题1 T4 二维码
组合 首先可以考虑一个状态合法的条件,可以发现的是最后得到的矩阵一定是至少有一行或是有一列全$0$或$1$,如果把这一列或这一行删掉那么将剩下的子矩阵拼接起来又是一个子问题,同样的也是至少有一列或一行 ...
- Android Studio导入github项目源码步骤
1.从github上将源码下载下来 2.打开AS,新建一个新项目(我选择了EmptyActivity) 3.先不要在AS 中打开源码,来整理源码 在源码的目录下面,将project下的build.gr ...
- 5、Python语法之基本数据类型
一 引入 我们学习变量是为了让计算机能够像人一样去记忆事物的某种状态,而变量的值就是用来存储事物状态的,很明显事物的状态分成不同种类的(比如人的年龄,身高,职位,工资等等),所以变量值也应该有不同的类 ...
- Inception系列之Inception_v1
目前,神经网络模型为了得到更好的效果,越来越深和越来越宽的模型被提出.然而这样会带来以下几个问题: 1)参数量,计算量越来越大,在有限内存和算力的设备上,其应用也就越难以落地. 2)对于一些数据集较少 ...
- leetcode 43:construct-binary-tree-from-inorder
题目描述 给出一棵树的中序遍历和后序遍历,请构造这颗二叉树 注意: 保证给出的树中不存在重复的节点 Given inorder and postorder traversal of a tree, c ...
- C++实现管理系统
概述 系统中需要实现的功能如下: 添加联系人:向通讯录中添加新人,信息包括(姓名.性别.年龄.联系电话.家庭住址)最多记录1000人 显示联系人:显示通讯录中所有的联系人信息 删除联系人:按照姓名进行 ...
- 【Flutter 1-7】Flutter教程Dart语言——变量
作者 | 弗拉德 来源 | 弗拉德(公众号:fulade_me) 2011年10月10日的GOTO大会上,谷歌的两位工程师发布了"Dart":Dart是一种全新的编程语言,旨在帮助 ...