栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3254 Corn Fields

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3254 Corn Fields

#include <iostream>#include <cstring>#include <stdlib.h>#include <stdio.h>using namespace std;const int MOD = 100000000;const int MAXN = 13;const int MAXSTATE = 8193;int dp[MAXN][MAXSTATE];int matrix[MAXN][MAXN];int vst[MAXSTATE];int vnum = 0, row = 0, col = 0;void getvalidstate(){    for(int i = 0; i < (1<<col); ++i)    {        if(0 == (i&(i<<1))) vst[vnum++] = i;    }}bool valid(int state, int r){    int rstate = 0;    for(int i = 1; i <= col; ++i)    {        if(matrix[r][i]) rstate += (1<<(col - i));    }    if(!(state&(~rstate)))        return true;    return false;}int main(){    int m, n, i, j;    while(EOF != scanf("%d%d", &m, &n)){    for(i = 1; i <= m; ++i)        for(j = 1; j <= n; ++j) scanf("%d", &matrix[i][j]);    row = m;    col = n;    vnum = 0;    getvalidstate();    memset(dp, 0, sizeof(int)*MAXN*MAXSTATE);    dp[0][0] = 1;    for(i = 1; i <= row; ++i)    {        for(int st = 0; st < vnum; ++st)        { if(valid(vst[st], i)) {     for(int pst = 0; pst < vnum; ++pst)     {         if(valid(vst[pst], i - 1) && !(vst[st]&vst[pst]))  dp[i][vst[st]] += dp[i - 1][vst[pst]];     } }        }    }    int ret = 0;    for(i = 0; i < vnum; ++i)    {        ret = (ret + dp[row][vst[i]])%MOD;    }    printf("%dn", ret);  }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374305.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号