您的位置:首页 > 其它

[HihoCoder]#1048 : 状态压缩·二

2016-07-31 21:45 253 查看
华电北风吹

天津大学认知计算与应用重点实验室

2016-07-31

题目链接:

http://hihocoder.com/problemset/problem/1048

题目分析:

基本的状态压缩类型题目。

参考代码:

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

#define MaxN 1005
#define Mod 1000000007

int state[MaxN][1 << 5];

bool Check(int s1, int s2, int m)
{
if ((s1&s2) > 0)
{
return false;
}
int s = s1 | s2;
int countNull = 0;
for (int i = 0; i < m; i++)
{
if (((1 << i) & s) == 0)
{
countNull++;
}
else
{
if (countNull & 1)
return false;
countNull = 0;
}
}
if (countNull & 1)
return false;
return true;
}

int main()
{
int N, M;
scanf("%d %d", &N, &M);
memset(state, 0, sizeof(state));
state[0][0] = 1;
for (int i = 1; i <= N; i++)
{
for (int j = 0; j < (1 << M); j++)
{
for (int k = 0; k < (1 << M); k++)
{
if (Check(k, j, M))
{
state[i][j] += state[i - 1][k];
state[i][j] = state[i][j] % Mod;
}
}
}
}
printf("%d\n", state
[0]);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: