hdu 4064 Carcassonne

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并重点阐述了AI音视频处理的应用场景和实现方法,如语义识别、物体检测、语音变声等。通过实例分析,揭示了技术融合带来的创新解决方案。
Problem Description
Carcassonne is a tile-based board game for two to five players.
Square tiles are printed by city segments,road segments and field segments.

The rule of the game is to put the tiles alternately. Two tiles share one edge should exactly connect to each other, that is, city segments should be linked to city segments, road to road, and field to field.

To simplify the problem, we only consider putting tiles:
Given n*m tiles. You can rotate each tile, but not flip top to bottom, and not change their order.
How many ways could you rotate them to make them follow the rules mentioned above?
 

Input
The first line is a number T(1<=T<=50), represents the number of case. The next T blocks follow each indicates a case.
Each case starts with two number N,M(0<N,M<=12)
Then N*M lines follow,each line contains M four-character clockwise.
'C' indicate City.
'R' indicate Road.
'F' indicate Field.
 

Output
For each case, output the number of ways mod 1,000,000,007.(as shown in the sample output)
 

Sample Input
  
3 1 1 RRRR 1 2 RRRF FCCC 8 8 FCFF RRFC FRCR FRFR RCCR FFCC RRFF CRFR FRRC FRFR CCCR FCFC CRRC CRRR FRCR FRFR RRCR FRRR CCCR FFFC RRFF RFCR CCFF FCCC CFCF RRFF CRFR FFRR FRRF CCRR FFFC CRRF CFRR FFFF FFFF RRFF RRRR RCRR FFCC RFRF RRCF FRFR FRRR FRFR RCCR RCCC CFFC RFRF CFCF FRFF RRFF FFFF CFFF CFFF FRFF RFRR CCRR FCFC FCCC FCCC FFCC FCCF FFCC RFRF
 

Sample Output
  
Case 1: 4 Case 2: 1 Case 3: 1048576
 

Source
 

Recommend
lcy




今天比赛5题鸭梨比较大,其中蒙了两题规律……orz……

这题是比较明显的状态dp,先预处理每一行有多少种可行的放法,对于某一种放法上面的状态为i,下面的状态为j,这样就有一种方法从状态i转移到状态j。

之后各种MLE……加了滚动数组之后TLE。

后来剪了枝,如果有某一块四面都一样的就不重复算,直接把ans乘以4,这样就可以过了。359MS,这个剪枝好强悍……

代码

#include <stdio.h>
#include <string.h>

#define MOD 1000000007

int map[15][15][5];
char str[5];
int n,m;
long long dp[2][600000];
int three[15];
bool flag;
int tag;


void DFS(int h,int t,int shang,int xia,int right)
{
    int i,j,n,ss,xx,zz,yy;
    if (t==m)
    {
      //  printf("%d..\n",tag);
        if (h==0)
        {
            dp[flag][xia]+=tag;
        }
        else
        {
            dp[flag][xia]=(dp[flag][xia]+dp[flag^1][shang]*tag)%MOD;
        }
        return;
    }
    zz=map[h][t][0];
    ss=map[h][t][1];
    yy=map[h][t][2];
    xx=map[h][t][3];
    if (zz==ss && zz==yy && zz==xx && ss==yy && ss==xx && yy==xx)
    {
        tag*=4;
        if (zz==right || right==-1) DFS(h,t+1,shang*3+ss,xia*3+xx,yy);
        tag/=4;
        return;
    }
    for (i=0;i<4;i++)
    {
        zz=map[h][t][(0+i)%4];
        ss=map[h][t][(1+i)%4];
        yy=map[h][t][(2+i)%4];
        xx=map[h][t][(3+i)%4];
        if (zz==right || right==-1) DFS(h,t+1,shang*3+ss,xia*3+xx,yy);
    }
}

int Change(char s)
{
    if (s=='C') return 0;
    if (s=='R') return 1;
    return 2;
}


int main()
{
    int i,j,T,k,kk,ans,cnt;
    cnt=1;
    three[0]=1;
    for (i=1;i<=13;i++)
    {
        three[i]=three[i-1]*3;
    }
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        for (i=0;i<n;i++)
        {
            for (j=0;j<m;j++)
            {
                scanf("%s",str);
                for (k=0;k<4;k++)
                {
                    map[i][j][k]=Change(str[k]);
                }
            }
        }
        memset(dp,0,sizeof(dp));
        flag=0;
        for (i=0;i<n;i++)
        {
            tag=1;
            DFS(i,0,0,0,-1);
            flag=1^flag;
            for (j=0;j<three[m];j++) dp[flag][j]=0;
        }
        ans=0;
        for (i=0;i<three[m];i++)
        {
            ans=(ans+dp[1^flag][i])%MOD;
        }
        printf("Case %d: %d\n",cnt++,ans);
    }
    return 0;
}



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值