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+ ...
随机推荐
- Win32编程之控制线程
0x01. 如何让线程停下来 让自己停下来: Sleep() 函数 当程序执行到某段代码的时候可以使用sleep() 函数进行暂停 使用sleep()函数挂起的时候会自动恢复过来的 让别人停下来: S ...
- Luogu P2179 [NOI2012]骑行川藏
题意 给定 \(n\) 个路段,每个路段用三个实数 \(s_i,k_i,v^\prime_i\) 描述,最小化 \[F(v_1,\cdots v_n)=\sum\limits_{i=1}^{n}\fr ...
- R语言删除不规范的值(或NA)
在使用R语言处理表格时(xlsx, csv),有时里面含有缺失值,或者不规范的数值,比如下图有许多的问号"?",为了便于处理数据,这些都应该整行地删掉. 为了删掉那些包含" ...
- 【实战分享】从选型到项目落地,漫谈 gRPC
什么是 gRPC? gRPC 的几种常见模式 在学习 gRPC 的时候,相信大家对于它的四种模式都有了解,我们来简单回顾一下: 简单模式(Simple RPC):这种模式最为传统,即客户端发起一次请求 ...
- 11content_processor
1,content_processor 上下文处理器应该返回一个字典,字典中的key会被模板中当成变量来渲染 上下文处理器返回的字典,在所有页面中都是可以使用的 被这个装饰器修饰的钩子函数,必须要返回 ...
- java enum 枚举值
public enum PieChartEnum { PIE00("pie00"), PIE10("pie10"), PIE11("pie11&quo ...
- Javascript 参数传递
又一个基本概念出问题,参数传递都是值传递, var a={x:10} function test(obj){obj=1} test(a) console.log(a) 输出什么,如果你说1,那就错了, ...
- 内核crash>>>磁盘空间小 怎么处理
在内存发生panic时,需要把panic的日志保存下来.以方便日后进行分析. 一般主机为x86的时候,panic 使用 kdump保存log.由于它使用占用大量内存和硬盘.所以当磁盘空间不够时,就会遇 ...
- 《GNU_Makefile》——第3章,Makefile总述
1.makefile的内容 一个完整的makefile包含5个东西: 显示规则,隐含规则,变量定义,指示符,注释 (1)显示规则 描述如何更新目标文件. (2)隐含规则 make程序内置的规则. ma ...
- mysql开发常用技巧总结
1.查询某个schema,某张表的创建时间. SELECT CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='db_camp ...