[poj 3254] Corn Fields  状态压缩DP(递推)

Corn Fields Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant. Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant. 立即下载

Corn Fields
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 11605 Accepted: 6078

Description

Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can’t be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant.

Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant.

Input
Line 1: Two space-separated integers: M and N
Lines 2..M+1: Line i+1 describes row i of the pasture with N space-separated integers indicating whether a square is fertile (1 for fertile, 0 for infertile)

Output
Line 1: One integer: the number of ways that FJ can choose the squares modulo 100,000,000.

Sample Input

2 3
1 1 1
0 1 0

Sample Output

9

Hint
Number the squares as follows:

1 2 3
4

There are four ways to plant only on one squares (1, 2, 3, or 4), three ways to plant on two squares (13, 14, or 34), 1 way to plant on three squares (134), and one way to plant on no squares. 4+3+1+1=9.

Source
USACO 2006 November Gold

题目链接:http://poj.org/problem?id=3254

题意:给你一个0,1矩阵,1代表可取,问不相邻取的方法数

思路:
1.明显的递推:dp[i][j]+=dp[i-1][p]..(前i行,第j状态的方法数)

2.n<=15—>状态压缩;

3.*优化,预处理可行状态:(相邻的处理)return x&(x<<1);存在st【】中;
判断2:上下return x&y;
判断3:与0,1图的匹配:

        scanf("%d",&aa);
        if(!aa)
        ma[i]+=(1<<(j-1));

若j状态在ma【i】中合法,st【j】&ma【i】==0

代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define N 13
#define M (1<<N)
#define mod  100000000
int st[M],ma[N];
int dp[N][M];
bool C(int x)
{
    return x&(x<<1);
}
bool can(int x,int y)
{
    return x&y;

}
int main()
{
    int n,m,x;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)   
    for(int j=1;j<=m;j++)
    {
        int aa;
        scanf("%d",&aa);
        if(!aa)
        ma[i]+=(1<<(j-1));
    }
    int k=0;
    for(int i=0;i<(1<<m);i++)
    if(!C(i))    st[++k]=i;
    for(int i=1;i<=k;i++)  
    if(!can(st[i],ma[1]))   dp[1][i]=1;

    for(int i=2;i<=n;i++)
    for(int j=1;j<=k;j++)
    {
        if(can(ma[i],st[j])) continue;
        for(int p=1;p<=k;p++)//枚举上一层的状态
        if(!can(ma[i-1],st[p])&&!can(st[j],st[p]))
        dp[i][j]+=dp[i-1][p];
    }   

    int ans=0;
    for(int i=1;i<=k;i++)
    {
        ans+=dp[n][i];
        ans%=mod;

    }
    printf("%d\n",ans);


}
告别混乱代码!在Arduino IDE中管理多文件项目的5个必备技巧 本文分享了在Arduino IDE中管理多文件项目的5个必备技巧,帮助开发者告别混乱代码。通过代码分割和模块化设计,提升编译效率、降低内存占用,并实现功能解耦。重点介绍了头文件设计、CPP文件实现、调试技巧和工业级目录结构,让你的Arduino项目像乐高积木一样清晰易维护。 阅读详情

相关推荐

鸿蒙手机卸载内置应用 adb连接

**傻瓜式删除鸿蒙系统内置应用,自己亲测有效。**

JJDXBT的博客 3万+

习题5-5:矩形分割(POJ 4136)(***)

问题链接:http://bailian.openjudge.cn/practice/4136/ 描述 平面上有一个大矩形,其左下角坐标(0,0),右上角坐标(R,R)。大矩形内部包含一些小矩形,小矩形都平行于坐标轴且互不重叠。所有矩形的顶点都是整点。要求画一根平行于y轴的直线x=k(k是整数),使得这些小矩形落在直线左边的面积必须大于等于落在右边的面积,且两边面积之差最小。并且,要使得大矩形...

jiangjiangjiang6的博客 982

栅格数据空间叠置分析题目步骤讲解

题目: 准备工作: ①新建数据库,将实验数据导入(利于后期矢量转栅格操作,未建数据库此步骤会一直出错); ②在工具条自定义窗口勾选spacial analyst模块,在菜单栏→扩展模块,勾选spacial analyst;确保实验后面的操作可以成功。 详细操作步骤: 1.对三个方案的规划路线(line.shp)建立50m缓冲区;打开ArcMap,在ArcToolBox→分析工具→邻域分析→缓冲区,打开缓冲区工具窗口,界面设置如图:线性单位填写50米,其余默认,单击“确定”。 ...

m0_57139844的博客 8895

【状压DP水题】[USACO06NOV]玉米田Corn Fields

题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squar...

bangzuan5029的博客 279

期末求生指南:手把手教你用浏览器开发者工具绕过百一测评切屏检测

本文详细介绍了如何利用浏览器开发者工具绕过百一测评的切屏检测功能。通过分析JavaScript事件监听机制,定位关键检测代码,并提供实时调试和本地覆盖两种修改方法,帮助学生在遵守规则的前提下更灵活地应对在线考试。文章还包含风险控制和替代方案等实用建议。

weixin_28698059的博客 551

[Linux外设驱动详解]RK3588 U-Boot网络功能深度分析

本文深入分析了RK3588平台上U-Boot的网络功能实现,主要内容包括: 网络架构:详细剖析了从硬件层到协议层的完整网络栈架构,包括GMAC驱动、TFTP/NFS启动、网络命令等关键组件。 驱动实现:重点介绍了RK3588 GMAC驱动结构,包含关键数据结构、专用操作函数集、设备树兼容性配置和GRF寄存器设置。 功能实现:详细说明了驱动初始化流程、RGMII速度适配机制以及PHY接口配置过程。 高级特性:涵盖了网络启动功能、镜像更新和MAC地址传递到Linux内核的机制。 文档通过代码片段和流程图清晰展示

Just Linux! 1115

POJ 3254 Corn Fields(状压DP)

Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. R...

muyu__的博客 253

【气动弹性实战】基于Nastran与Patran的机翼颤振仿真:从模态分析到临界速度预测

本文详细介绍了基于Nastran与Patran的机翼颤振仿真全流程,从气动弹性问题解析、机翼建模技巧到模态分析与临界速度预测。通过实战案例展示如何利用SOL 145求解器进行颤振分析,并分享网格划分、材料属性设置等工程经验,帮助工程师有效解决飞行器设计中的气动弹性耦合问题。

weixin_33725722的博客 597

【状压dp】 POJ - 3254 Corn Fields

Corn Fields  POJ - 3254  Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number ...

qq_41037114的博客 236

群晖设置公网ipv6方式域名解析访问

群晖、IPV6、域名解析

爬山虎的博客 2万+

Matlab 曲面平滑与点云处理

曲面平滑是一种常见的数学和计算机图形学技术,可以用来消除噪声、填补数据间隙,以及改善曲面的外观。在点云处理中,曲面平滑也被广泛应用于重建、拟合和可视化等领域。本文将介绍如何使用 Matlab 进行曲面平滑和点云处理,并提供相应的源代码。通过以上步骤,我们可以使用 Matlab 进行曲面平滑和点云处理。你可以根据具体需求调整参数和算法,以获得理想的曲面平滑效果。接下来,我们可以使用平滑算法对三角化的网格进行曲面平滑。以上代码将绘制原始点云和重建后的点云,并在图形中显示坐标轴和图例。表示平滑的迭代次数。

QfcaLinux的博客 753

POJ - 3254 (2020.4.23训练B题)

Problem Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regre...

rainbowower的博客 391

YOLO26涨点改进 | 独家主干改进篇 | CVPR 2024 | YOLO26利用InceptionNeXt主干,将大核深度卷积分解为四个并行分支,在提升性能的同时显著降低计算效率

本文聚焦YOLO26的核心涨点改进——基于CVPR 2024收录的InceptionNeXt主干网络,深度拆解了其“大核深度卷积四分支拆解”的核心逻辑,通过实验验证了改进的有效性,同时提供了可快速复现的工程代码与进一步涨点的思路。

qq_36130719的博客 574

POJ3254 Corn Fields 状态压缩DP

第二道状态压缩DP,虽然不难,但还是想了很久。 递推方程 dp[s][i] =Σ dp[s'][i-1]   dp[s][i]表示第i行状态为s时一共有多少种方案,从第一行开始向下递推。 这里要注意 可以用一个数组先把每一行中符合要求的情况全部记录,这样可以有效减少状态,和循环。另外题目要求我们取模,这里要注意。   Corn Fields Time Limit: 2

1116

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

初识状态压缩dp poj3254 Corn Fields

hello,world!

Na_OH的博客 440

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

poj 3254 Corn Fields (状态压缩DP)

题目:http://poj.org/problem?id=3254 思路见代码: #include<iostream> using namespace std; const int MOD=100000000; const int MAX_N_M=12; int row_state[MAX_N_M]; // 枚举出合法的状态数 int LegalState[...

weixin_30273175的博客 119

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

POJ 3254 Corn Fields

<br />记录状态的DP.<br />每一行的状态有2^12种可能(其中一部分状态是无效的),且与前一行的状态相关,<br />题目要求计算的可以理解为到达最后一行各个有效状态的次数之和。<br />输入1 for fertile, 0 for infertile,为了计算方便进行取反,0 for fertile, 1 for infertile。<br /><br /><br />/*Corn Fields Time Limit: 2000MS Memory Limit: 65536K Tota

mimo9527的专栏 847

Corn Fields(poj3254)状态压缩dp

Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12738   Accepted: 6681 Description Farmer John has purchased a lush new rectangular pasture compo

相思作坊半世离殇的博客 400

POJ3254-Corn Fields(状压DP)

题目链接:http://poj.org/problem?id=3254 思路:把每行的状态转化成一个二进制数,每个数代表一种放置方法,dp[i][j]=Σdp[i-1][k](k为满足条件的放置方法)。 #include using namespace std; const int MOD=1e8; int dp[13][(1<<12)+5]; int a[13],b[(1<<12)+5];

West___wind的博客 373

poj-3254 Corn Fields(状态压缩dp)

Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20342   Accepted: 10679 Description Farmer John has purchased a lush new rectangular pasture composed of M by...

qq_37378303的博客 209

Corn Fields POJ - 3254 (状压dp)

题目链接: Corn Fields POJ - 3254 题目大意:给你一个n*m的矩阵,矩阵的元素只包括0和1,0代表当前的位置不能放置人,1代表当前的位置可以放人,当你决定放人的时候,这个人的四个方向都不能放人,然后问你一共有多少种放置方式。 具体思路:二进制枚举,每一次判断和上下左右位置是否冲突就好了。 AC代码: 1 #include<iostream...

diaomeijiao3430的博客 122

poj 3254 Corn Fields(状态压缩DP)

题目地址 题目大意:一个row*col的矩阵,每个格子是0或者1,1表示土壤肥沃可以种植草地,0则不可以。在种草地的格子可以放牛,但边相邻的两个格子不允许同时放牛,问总共有多少种放牛的方法?(不放牛也算一种情况) 解题思路:状态压缩DP。dp[r][k]表示第r行处于状态k时,前r行的情况数总和 #include #include #include #include

booyoungxu的专栏 258

(POJ 3254)Corn Fields <状态压缩DP 好题>

Corn Fields DescriptionFarmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of

STILLxjy 574

【原创】【状态压缩DP】POJ3254 Corn Fields【新手向】

【原创】【状态压缩DP】POJ3254 Corn Fields【新手向】 一开始根本不会状压dp,上网各种找题解,但发现他们写的都很......反正我作为一个没有接触过状态压缩的,根本看不懂! 然后看了好多状态压缩的题的题解,总结了一下思路,思路很重要,有了思路转换成计算机语言就好了。因此我先讲一下思路:   先说说地图,地图上每一行的0...

swallowblank的博客 159

poj 3254 Corn Fields【状态压缩dp】【入门第一题~~】

Corn FieldsTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 17938 Accepted: 9447DescriptionFarmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12)...

loving coding 329

【DP】 poj3254 Corn Fields

Corn Fields http://poj.org/problem?id=3254 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow

Ted's 游乐园 889
上一篇: [poj 3034] Whac-a-Mole  dp
下一篇: 【poj 2411】Mondriaan's Dream 状态压缩DP
ALPS233
博客等级 码龄11年 25粉丝 191原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值