zoukankan      html  css  js  c++  java
  • LOJ#2954. 「NOIP2018」填数游戏 打表+搜索

    1 ~ 6 的都跑完了,7 的还没跑出来. 

    code1: 

    #include <bits/stdc++.h>   
    #define ll long long 
    #define mod 998244353
    #define setIO(s) freopen(s".in","r",stdin) 
    using namespace std;       
    int a[10][10],n,m,ans,flag; 
    ll maxx;   
    int solve(int x,int y,ll cur) 
    {
        if(x==n&&y==m) 
        {
            if(maxx==-1) 
                maxx=cur;   
            else if(maxx>cur) { flag=1;   return 0; }   
            else maxx=max(maxx,cur);   
            return 1;  
        }
        int cu=1;  
        if(y<m) cu&=solve(x,y+1,cur*10+a[x][y+1]);    
        if(!cu) return 0; 
        if(x<n) cu&=solve(x+1,y,cur*10+a[x+1][y]);      
        return cu;   
    }
    void cal() 
    {       
        maxx=-1,flag=0;         
        solve(1,1,a[1][1]); 
        ans+=(!flag);    
        // if(!flag) printf("%d
    ",ans);      
    }
    void dfs(int x,int y) 
    {
        for(int i=0;i<2;++i) 
        { 
            if(x-1>=1&&y+1<=m&&a[x-1][y+1]>i) continue;   
            a[x][y]=i;         
            if(x==n&&y==m) cal(); 
            else if(y==m) dfs(x+1,1);     
            else dfs(x,y+1);  
        }  
    }
    int main() 
    { 
        setIO("input");
        // freopen("input.out","w",stdout);   
        scanf("%d%d",&n,&m);   
        dfs(1,1);   
        printf("%d
    ",ans);  
        return 0; 
    }
    

      

    code2: 

    #include <bits/stdc++.h>    
    #define ll long long  
    #define mod 1000000007  
    #define setIO(s) freopen(s".in","r",stdin)  
    using namespace std; 
    int n,m;   
    ll qpow(int x,int y) 
    {
        ll tmp=1;  
        for(;y;y>>=1,x=(ll)x*x%mod) if(y&1) tmp=(ll)tmp*x%mod;  
        return tmp;    
    } 
    void calc3() 
    {
        return;  
    }
    int main() 
    { 
        // setIO("input"); 
        freopen("game.in","r",stdin); 
        freopen("game.out","w",stdout);   
        scanf("%d%d",&n,&m);
        if(n==1) printf("%lld
    ",qpow(2,m));     
        else if(n==2) printf("%lld
    ",4ll*qpow(3,m-1)%mod);     
        else if(n==3) 
        {  
            if(m==1) printf("%d
    ",8);  
            else if(m==2) printf("%d
    ",36);  
            else if(m==3) printf("%d
    ",112);   
            else printf("%lld
    ",1ll*112*qpow(3,m-3)%mod);   
        } 
        else if(n==4) 
        {
            if(m==1) printf("16
    ");  
            else if(m==2) printf("108
    ");  
            else if(m==3) printf("336
    ");  
            else if(m==4) printf("912
    ");  
            else if(m==5) printf("2688
    ");  
            else if(m==6) printf("8064
    ");  
            else printf("%lld
    ",1ll*8064*qpow(3,m-6)%mod);    
        }
        else if(n==5)
        {
            if(m==1) printf("32
    ");  
            else if(m==2) printf("324
    ");  
            else if(m==3) printf("1008
    ");  
            else if(m==4) printf("2688
    ");  
            else if(m==5) printf("7136
    ");   
            else if(m==6) printf("21312
    ");  
            else printf("%lld
    ",1ll*21312*qpow(3,m-6)%mod);   
        }
        else if(n==6) 
        {
            if(m==1) printf("64
    ");  
            else if(m==2) printf("972
    ");   
            else if(m==3) printf("3024
    ");  
            else if(m==4) printf("8064
    ");  
            else if(m==5) printf("21312
    ");  
            else if(m==6) printf("56768
    ");    
            else if(m==7) printf("170112
    ");   
            else if(m==8) printf("510336
    ");  
            else printf("%lld
    ",1ll*510336*qpow(3,m-8)%mod);   
        }
        else if(n==7) 
        {
            
        }
        return 0; 
    }
    

      

    7:  

    128

    2916

    9072

    24192

    63936

    170112

    453504    

  • 相关阅读:
    TortoiseSVN 使用详细步骤(三):安装
    TortoiseSVN使用详细步骤(二)
    TortoiseSVN使用详细步骤(一)
    IIS7下访问ashx页面,显示404
    Learning Python 008 正则表达式-003 search()方法
    Learning Python 008 正则表达式-002 findall()方法
    Learning Python 008 正则表达式-001
    Learning Python 007 基本语句
    Learning Python 006 list(列表) 和 tuple(元组)
    Learning Python 005 字符串和编码
  • 原文地址:https://www.cnblogs.com/guangheli/p/13138784.html
Copyright © 2011-2022 走看看