HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem H. Dominoes

简介: HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem H. Dominoes

Problem H.Dominoes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 17    Accepted Submission(s): 12



Problem Description


Orz likes to play dominoes. Now giving an n\*m chessboard and k dominoes whose size are 1\*2, Orz finds that there is exactly one grid empty, so that he can move dominoes without overlapping them. An initial situation is given, he wants to know how many final situation could be achieved, except the initial situation. Note every domino is different, as they have their own serial number. Since the answer may be very large, please output the answer modulo 1000000009.


Input


There will be multiple test cases. For each test case:

The first line contains three integers: n,m,k(n≤9,m≤10000).

The following k lines, each line contains four integers: a \ b \ c \ d, indicating that this domino occupies (a, b) and (c, d).

The input guarantees that the domino does not overlap, and there is exactly one empty grid.


Output


For each test cases, output the answer modulo 1000000009.


Sample Input

5 5 12

1 1 2

1 1 2

2 2 1

3 2 3

1 4 1

5 2 4

2 5 3

4 3 5

3 1 3

2 4 1

4 2 5

1 5 2

4 3 5

3 4 4

5 4 4

5 5 5


Sample Output

8


解题思路:找规律可发现一块多米诺骨牌最多只会动一次除非往反方向走,又因为骨牌动一下等于空格向上、下、左、右方向移动两格,所以直接宽度优先搜索空格可以到的位置有多少个就是有多少解。


AC 代码


/

#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int dir[4][2]={1,0,-1,0,0,1,0,-1};
queue<pii> q;
int n,m,k,ans; // 撑死 90000,不需mod
int mp[20][10100];
void init()
{
    ans=0;
    mem(mp,0);
    while(!q.empty()) q.pop();
}
void bfs()
{
    int flag=1;
    for(int i=1;i<=n&&flag;i++)
        for(int j=1&&flag;j<=m;j++)
            if(!mp[i][j])
            {
                flag=0;
                q.push(make_pair(i,j));
            }
    int x,y;
    while(!q.empty())
    {
        x=q.front().first, y=q.front().second; q.pop();
        for(int i=0;i<4;i++)
        {
            // mp[x+dir[i][0]][y+dir[i][1]]!=0 原本以为不用加,后来发现少考虑一种情况:空格满图“跑”的时候,回到第一次的空格(若不加此条件)就死循环了
            if(mp[x+dir[i][0]][y+dir[i][1]]!=0 && mp[x+dir[i][0]][y+dir[i][1]]==mp[x+dir[i][0]*2][y+dir[i][1]*2])
            {
                ans++;
                q.push(make_pair(x+dir[i][0]*2,y+dir[i][1]*2));
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        init();
        int a,b,c,d;
        for(int i=0,th=1;i<k;i++)
        {
            scanf("%d%d%d%d",&a,&b,&c,&d);
            mp[a][b]=mp[c][d]=th++;
        }
        bfs();
        printf("%d\n",ans);
    }
    return 0;
}
目录
相关文章
|
C++ 网络架构
【PAT甲级 - C++题解】1013 Battle Over Cities
【PAT甲级 - C++题解】1013 Battle Over Cities
62 1
2022天梯赛三月冲刺——PAT (Advanced Level)1013 Battle Over Cities (并查集找连通块)
2022天梯赛三月冲刺——PAT (Advanced Level)1013 Battle Over Cities (并查集找连通块)
105 0
|
C++
【PAT甲级 - C++题解】1061 Dating
【PAT甲级 - C++题解】1061 Dating
70 0
UPC组队赛第三场——G: The Famous ICPC Team Again (主席树)
UPC组队赛第三场——G: The Famous ICPC Team Again (主席树)
100 0
[SDUT 2414] | 山东省第三届省赛 An interesting game | 最小费用最大流
题目描述 Xiao Ming recently designs a little game, in front of player there are N small hillsides put in order, now Xiao Ming wants to increase some hillsides to block the player, so he prepared another M hillsides, but he does not hope it will be too difficult,
164 0
[SDUT 2414] | 山东省第三届省赛 An interesting game | 最小费用最大流
|
人工智能 安全
UPC-2021个人训练赛第20场-部分题解
RGB Triplets 题目描述 输入 输出 样例输入 Copy 样例输出 Copy 提示 Select Half 题目描述 输入 输出 样例输入 Copy 样例输出 Copy 提示 心灵的抚慰 题目描述 输入 输出 样例输入 Copy 样例输出 Copy 提示
168 0
|
机器学习/深度学习 算法 Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem B. Bullet
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem B. Bullet
168 0
|
Java Go
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem E. Travel
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem E. Travel
125 0
|
人工智能 Java BI
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem D. Team Name
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem D. Team Name
128 0
|
Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem F. Four-tuples
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem F. Four-tuples
142 0