博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(最小路径覆盖) poj 2446
阅读量:4975 次
发布时间:2019-06-12

本文共 2365 字,大约阅读时间需要 7 分钟。

E - Chessboard
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit     

Description

Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy to bob, so she makes some holes on the board (as shown in the figure below). 
We call a grid, which doesn’t contain a hole, a normal grid. Bob has to follow the rules below: 
1. Any normal grid should be covered with exactly one card. 
2. One card should cover exactly 2 normal adjacent grids. 
Some examples are given in the figures below: 
A VALID solution.
An invalid solution, because the hole of red color is covered with a card.
An invalid solution, because there exists a grid, which is not covered.
Your task is to help Bob to decide whether or not the chessboard can be covered according to the rules above.

Input

There are 3 integers in the first line: m, n, k (0 < m, n <= 32, 0 <= K < m * n), the number of rows, column and holes. In the next k lines, there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th column.

Output

If the board can be covered, output "YES". Otherwise, output "NO".

Sample Input

4 3 22 13 3

Sample Output

YES

Hint

A possible solution for the sample input.
 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int mp[1230][1230],link[1230],mark[1230],g[35][35],ans,opt[35][35];int n,m,k,temp;bool dfs(int x){ for(int i=1;i<=temp;i++) { if(mark[i]==-1&&mp[x][i]) { mark[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=x; return true; } } } return false;}int main(){ int x,y; while(scanf("%d%d%d",&n,&m,&k)!=EOF) { temp=0; ans=0; memset(link,-1,sizeof(link)); memset(g,0,sizeof(g)); memset(opt,0,sizeof(opt)); for(int i=1;i<=k;i++) { scanf("%d%d",&y,&x); opt[x][y]=1; } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(!opt[i][j]) { g[i][j]=++temp; } } } memset(mp,0,sizeof(mp)); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(g[i][j]!=0) { if(i>1&&g[i-1][j]!=0) mp[g[i][j]][g[i-1][j]]=1; if(i
1&&g[i][j-1]!=0) mp[g[i][j]][g[i][j-1]]=1; if(j

  

转载于:https://www.cnblogs.com/water-full/p/4460965.html

你可能感兴趣的文章
个人阅读作业7
查看>>
转载:深入浅出Zookeeper
查看>>
GMA Round 1 新程序
查看>>
node anyproxy ssi简易支持
查看>>
编译预处理指令:文件包含指令、宏定义指令、条件编译指令
查看>>
PHP函数 ------ ctype_alnum
查看>>
网站安全
查看>>
WS-Addressing 初探
查看>>
.NET+模块编排+数据库操作类的封装+分层架构+实体类+Ajax.net+Athem.NET+javascript+Activex组件+用户权限等...
查看>>
Markdown不常见功能
查看>>
(二)NUnit单元测试心得
查看>>
hdu_2604Queuing(快速幂矩阵)
查看>>
frame.bounds和center
查看>>
HDU 1102 Constructing Roads
查看>>
android StaticLayout参数解释
查看>>
多线程之ThreadLocal类
查看>>
Qt-读取文本导出word
查看>>
OC语言description方法和sel
查看>>
C#中得到程序当前工作目录和执行目录的五种方法
查看>>
扫描线与悬线
查看>>