[DLX精确覆盖+打表] hdu 2518 Dominoes
题意:
就是给12种图形,旋转,翻折。有多少种方法构成n*m=60的矩形
思路:
裸的精确覆盖。就是建图麻烦
个人太挫,直接手写每一个图形的各种形态
须要注意的是最后的答案须要除以4
代码:
#include"stdio.h"
#include"algorithm"
#include"string.h"
#include"iostream"
#include"queue"
#include"map"
#include"vector"
#include"string"
using namespace std;
/*int mp[63][5][5]=
{
{
//1.1
{1,0,0},
{1,0,0},
{1,1,1},
},
{
//1.2
{1,1,1},
{0,0,1},
{0,0,1},
},
{
//1.3
{0,0,1},
{0,0,1},
{1,1,1},
},
{
//1.4
{1,1,1},
{1,0,0},
{1,0,0},
},
{
//2.5
{1,1,1,1,1},
},
{
//2.6
{1},
{1},
{1},
{1},
{1},
},
{
//3.7
{0,1,0},
{1,1,1},
{0,1,0},
},
{
//4.8
{1,1,1},
{1,0,1},
},
{
//4.9
{1,0,1},
{1,1,1},
},
{
//4.10
{1,1},
{1,0},
{1,1},
},
{
//4.11
{1,1},
{0,1},
{1,1},
},
{
//5.12
{1,1,1,1},
{1,0,0,0},
},
{
//5.13
{1,0},
{1,0},
{1,0},
{1,1},
},
{
//5.14
{0,0,0,1},
{1,1,1,1},
},
{
//5.15
{1,1},
{0,1},
{0,1},
{0,1},
},
{
//5.16
{1,0,0,0},
{1,1,1,1},
},
{
//5.17
{0,1},
{0,1},
{0,1},
{1,1},
},
{
//5.18
{1,1,1,1},
{0,0,0,1},
},
{
//5.19
{1,1},
{1,0},
{1,0},
{1,0},
},
{
//6.20
{1,0,0},
{1,1,0},
{0,1,1},
},
{
//6.21
{0,0,1},
{0,1,1},
{1,1,0},
},
{
//6.22
{1,1,0},
{0,1,1},
{0,0,1},
},
{
//6.23
{0,1,1},
{1,1,0},
{1,0,0},
},
{
//7.24
{1,1,1,1},
{0,1,0,0},
},
{
//7.25
{1,0},
{1,0},
{1,1},
{1,0},
},
{
//7.26
{0,0,1,0},
{1,1,1,1},
},
{
//7.27
{0,1},
{1,1},
{0,1},
{0,1},
},
{
//7.28
{0,1,0,0},
{1,1,1,1},
},
{
//7.29
{0,1},
{0,1},
{1,1},
{0,1},
},
{
//7.30
{1,1,1,1},
{0,0,1,0},
},
{
//7.31
{1,0},
{1,1},
{1,0},
{1,0},
},
{
//8.32
{0,0,1},
{1,1,1},
{1,0,0},
},
{
//8.33
{1,1,0},
{0,1,0},
{0,1,1},
},
{
//8.34
{1,0,0},
{1,1,1},
{0,0,1},
},
{
//8.35
{0,1,1},
{0,1,0},
{1,1,0},
},
{
//9.36
{0,1,0},
{0,1,1},
{1,1,0},
},
{
//9.37
{0,1,0},
{1,1,1},
{0,0,1},
},
{
//9.38
{0,1,1},
{1,1,0},
{0,1,0},
},
{
//9.39
{1,0,0},
{1,1,1},
{0,1,0},
},
{
//9.40
{1,1,0},
{0,1,1},
{0,1,0},
},
{
//9.41
{0,1,0},
{1,1,1},
{1,0,0},
},
{
//9.42
{0,1,0},
{1,1,0},
{0,1,1},
},
{
//9.43
{0,0,1},
{1,1,1},
{0,1,0},
},
{
//10.44
{0,1,0},
{0,1,0},
{1,1,1},
},
{
//10.45
{1,1,1},
{0,1,0},
{0,1,0},
},
{
//10.46
{0,0,1},
{1,1,1},
{0,0,1},
},
{
//10.47
{1,0,0},
{1,1,1},
{1,0,0},
},
{
//11.48
{0,1,1},
{1,1,1},
},
{
//11.49
{1,1},
{1,1},
{0,1},
},
{
//11.50
{1,1,1},
{1,1,0},
},
{
//11.51
{1,0},
{1,1},
{1,1},
},
{
//11.52
{1,1,1},
{0,1,1},
},
{
//11.53
{1,1},
{1,1},
{1,0},
},
{
//11.54
{1,1,0},
{1,1,1},
},
{
//11.55
{0,1},
{1,1},
{1,1},
},
{
//12.56
{0,1,1,1},
{1,1,0,0},
},
{
//12.57
{1,0},
{1,0},
{1,1},
{0,1},
},
{
//12.58
{0,0,1,1},
{1,1,1,0},
},
{
//12.59
{1,0},
{1,1},
{0,1},
{0,1},
},
{
//12.60
{1,1,1,0},
{0,0,1,1},
},
{
//12.61
{0,1},
{1,1},
{1,0},
{1,0},
},
{
//12.62
{1,1,0,0},
{0,1,1,1},
},
{
//12.63
{0,1},
{0,1},
{1,1},
{1,0},
},
};
//a代表每一个的行,b代表每一个的列。c代表每一个属于哪种
int a[]= {3,3,3,3,1,5,3,2,2,3,3,2,4,2,4,2,4,2,4,3,3,3,3,2,4,2,4,2,4,2,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,2,3,2,3,2,3,2,4,2,4,2,4,2,4};
int b[]= {3,3,3,3,5,1,3,3,3,2,2,4,2,4,2,4,2,4,2,3,3,3,3,4,2,4,2,4,2,4,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,2,3,2,3,2,4,2,4,2,4,2,4,2};
int c[]= {1,1,1,1,2,2,3,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12};
#define N 63*66*(60+66+14)
#define M 63*66
int ooo,haha;
struct DLX
{
int n,m,C;
int U[N],D[N],L[N],R[N],Row[N],Col[N];
int H[M],S[M],cnt,ans[M];
void init(int _n,int _m)
{
n=_n;
m=_m;
for(int i=0; i<=m; i++)
{
U[i]=D[i]=i;
L[i]=(i==0?m:i-1);
R[i]=(i==m? 0:i+1);
S[i]=0;
}
C=m;
for(int i=1; i<=n; i++) H[i]=-1;
}
void link(int x,int y)
{
C++;
Row[C]=x;
Col[C]=y;
S[y]++;
U[C]=U[y];
D[C]=y;
D[U[y]]=C;
U[y]=C;
if(H[x]==-1) H[x]=L[C]=R[C]=C;
else
{
L[C]=L[H[x]];
R[C]=H[x];
R[L[H[x]]]=C;
L[H[x]]=C;
}
}
void del(int x)
{
R[L[x]]=R[x];
L[R[x]]=L[x];
for(int i=D[x]; i!=x; i=D[i])
{
for(int j=R[i]; j!=i; j=R[j])
{
U[D[j]]=U[j];
D[U[j]]=D[j];
S[Col[j]]--;
}
}
}
void rec(int x)
{
for(int i=U[x]; i!=x; i=U[i])
{
for(int j=L[i]; j!=i; j=L[j])
{
U[D[j]]=j;
D[U[j]]=j;
S[Col[j]]++;
}
}
R[L[x]]=x;
L[R[x]]=x;
}
void dance(int x)
{
if(R[0]==0 || R[0]>ooo)
{
haha++;
//cnt=x;
return ;
}
int now=R[0];
for(int i=R[0]; i!=0 && i<=ooo; i=R[i])
{
if(S[i]<S[now]) now=i;
}
del(now);
for(int i=D[now]; i!=now; i=D[i])
{
//ans[x]=Row[i];
for(int j=R[i]; j!=i; j=R[j]) del(Col[j]);
dance(x+1);
for(int j=L[i]; j!=i; j=L[j]) rec(Col[j]);
}
rec(now);
return ;
}
} dlx;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=-1)
{
int cnt=0;
ooo=60;
dlx.init(63*60*5,60+12);
for(int i=0; i<63; i++)
{
for(int xx=1; xx+a[i]<=n+1; xx++)
{
for(int yy=1; yy+b[i]<=m+1; yy++)
{
cnt++;
// if(c[i]<5) printf("%d:",c[i]);
for(int x=0; x<a[i]; x++)
{
for(int y=0; y<b[i]; y++)
{
if(mp[i][x][y]==1)
{
int tep=(xx+x-1)*m+(yy+y);
// if(c[i]<5)printf("%d ",tep);
dlx.link(cnt,tep);
}
}
}
//if(c[i]<5) puts("");
dlx.link(cnt,60+c[i]);
}
}
} haha=0;
dlx.dance(0);
printf("%d\n",haha);
}
return 0;
}*/
int ans[]={0,0,0,2,368,1010,2339};
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=-1)
{
if(n>m) swap(n,m);
printf("%d\n",ans[n]);
}
return 0;
}
[DLX精确覆盖+打表] hdu 2518 Dominoes的更多相关文章
- DLX精确覆盖与重复覆盖模板题
hihoCoder #1317 : 搜索四·跳舞链 原题地址:http://hihocoder.com/problemset/problem/1317 时间限制:10000ms 单点时限:1000ms ...
- 【转】DLX 精确覆盖 重复覆盖
问题描述: 给定一个n*m的矩阵,有些位置为1,有些位置为0.如果G[i][j]==1则说明i行可以覆盖j列. Problem: 1)选定最少的行,使得每列有且仅有一个1. 2)选定最少的行,使得每列 ...
- POJ 3076 Sudoku DLX精确覆盖
DLX精确覆盖模具称号..... Sudoku Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 4416 Accepte ...
- (简单) POJ 3074 Sudoku, DLX+精确覆盖。
Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgr ...
- (简单) HUST 1017 Exact cover , DLX+精确覆盖。
Description There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is ...
- poj3074 DLX精确覆盖
题意:解数独 分析: 完整的数独有四个充要条件: 1.每个格子都有填数字 2.每列都有1~9中的每个数字 3.每行都有1~9中的每个数字 4.每个9宫格都有1~9中的每个数字 可以转化成精确覆盖问题. ...
- POJ 3074 Sudoku DLX精确覆盖
DLX精确覆盖.....模版题 Sudoku Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8336 Accepted: ...
- [DLX精确覆盖] hdu 1603 A Puzzling Problem
题意: 给你n块碎片,这些碎片不能旋转.翻折. 问你能不能用当中的某些块拼出4*4的正方形. 思路: 精确覆盖裸题了 建图就是看看每一个碎片在4*4中能放哪些位置,这个就作为行. 列就是4*4=16个 ...
- [DLX精确覆盖] hdu 3663 Power Stations
题意: 给你n.m.d,代表有n个城市.m条城市之间的关系,每一个城市要在日后d天内都有电. 对于每一个城市,都有一个发电站,每一个发电站能够在[a,b]的每一个连续子区间内发电. x城市发电了.他相 ...
随机推荐
- vue实现tab栏切换
html <ul class="tab"> <li v-for="(item,index) in tabs" @click="tab ...
- 小程序canvas生成二维码图片踩的坑
1:生成临时图片,保证画布被加载以及渲染(即本身不可以 hidden 或是 上级元素不可以 hidden 或是 wx:if 隐藏等) == > 建议:因为 canvas 的组件层级(z-inde ...
- Oralce中的package和package body
1.Oracle Package的作用: 可以简化应用设计.提高应用性能.实现信息隐藏.子程序重载 2.ORACLE中的function .package.package bodies.pro ...
- OpenJDK源码研究笔记(五)-缓存Integer等类型的频繁使用的数据和对象,大幅度提升性能(一道经典的Java笔试题)
摘要 本文先给出一个看似很简单实则有深意的Java笔试面试题,引出JDK内部的缓存. JDK内部的缓存,主要是为了提高Java程序的性能. 你能答对这道"看似简单,实则有深意"的J ...
- CodeForces 453A
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she ...
- HDU 1532||POJ1273:Drainage Ditches(最大流)
pid=1532">Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- jackson 解析json含有不规则的属性的json字符串的方法
对于json中含有点号,等其它特殊的,不是规范的java变量名的字符,能够使用一个注解来处理. 贴代码: import com.fasterxml.jackson.annotation.JsonPro ...
- 开源 java CMS - FreeCMS2.3会员个人资料
原文地址:http://javaz.cn/site/javaz/site_study/info/2015/28577.html 项目地址:http://www.freeteam.cn/ 个人资料 从 ...
- Thinkphp 无法使用->order() 排序的两种解决的方法!
使用ThinkPHP,却发现无法使用->order($order)来排序. $order = " info.date2 desc "; 非常遗憾的是这样写结果order却变成 ...
- display的几种常用取值
display的取值有很多种,下面列出比较常用的几种取值,还有其它的少用的值没有列出来: 1.none 此元素不会被显示,并且不占据页面空间,这也是与visibility:hidden不同的地方,设置 ...