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\n",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\n",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\n",qpow(2,m));     
    else if(n==2) printf("%lld\n",4ll*qpow(3,m-1)%mod);     
    else if(n==3) 
    {  
        if(m==1) printf("%d\n",8);  
        else if(m==2) printf("%d\n",36);  
        else if(m==3) printf("%d\n",112);   
        else printf("%lld\n",1ll*112*qpow(3,m-3)%mod);   
    } 
    else if(n==4) 
    {
        if(m==1) printf("16\n");  
        else if(m==2) printf("108\n");  
        else if(m==3) printf("336\n");  
        else if(m==4) printf("912\n");  
        else if(m==5) printf("2688\n");  
        else if(m==6) printf("8064\n");  
        else printf("%lld\n",1ll*8064*qpow(3,m-6)%mod);    
    }
    else if(n==5)
    {
        if(m==1) printf("32\n");  
        else if(m==2) printf("324\n");  
        else if(m==3) printf("1008\n");  
        else if(m==4) printf("2688\n");  
        else if(m==5) printf("7136\n");   
        else if(m==6) printf("21312\n");  
        else printf("%lld\n",1ll*21312*qpow(3,m-6)%mod);   
    }
    else if(n==6) 
    {
        if(m==1) printf("64\n");  
        else if(m==2) printf("972\n");   
        else if(m==3) printf("3024\n");  
        else if(m==4) printf("8064\n");  
        else if(m==5) printf("21312\n");  
        else if(m==6) printf("56768\n");    
        else if(m==7) printf("170112\n");   
        else if(m==8) printf("510336\n");  
        else printf("%lld\n",1ll*510336*qpow(3,m-8)%mod);   
    }
    else if(n==7) 
    {
        
    }
    return 0; 
}

  

7:  

128

2916

9072

24192

63936

170112

453504    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值