• 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
    ");
    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
    ");
    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
    ",1ll*dp[n][m]*dp[n][m]%mod);
        }
        return 0;
    }
    
    
    卷也卷不过,躺又躺不平
  • 相关阅读:
    HDU1196 ZOJ2417 Lowest Bit
    HDU1008 ZOJ2108 Elevator
    HDU2614 Beat
    HDU2057 A + B Again
    POJ3984 迷宫问题
    HDU1013 POJ1519 Digital Roots
    HDU2051 Bitset
    HDU2037 今年暑假不AC
    ACM入门练习与递推小结
    HDU2046 骨牌铺方格【递推】
  • 原文地址:https://www.cnblogs.com/hunxuewangzi/p/13766527.html
Copyright © 2020-2023  润新知