首页 技术 正文
技术 2022年11月8日
0 收藏 806 点赞 1,876 浏览 1889 个字
Farmer John has purchased a lush new rectangular pasture composed of M by N ( ≤ M ≤ ;  ≤ N ≤ ) 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 : Two space-separated integers: M and N
Lines .. M+: Line i+ describes row i of the pasture with N space-separated integers indicating whether a square is fertile ( for fertile, for infertile)
Output
Line : One integer: the number of ways that FJ can choose the squares modulo ,,.
Sample InputSample OutputHint
Number the squares as follows: There are four ways to plant only on one squares (, , , or ), three ways to plant on two squares (, , or ), way to plant on three squares (), and one way to plant on no squares. +++=.

被hdu 多校第3场c题教育了,来刷状压dp

先处理下所有的满足的状态;i&i<<1

然后和上一个状态比较。满足的状态里选出和上一行满足的状态

#include <cstdio>
#include <cstring>
#include <iostream>
//#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
//#define mod 998244353
const int mod=;
int low[];
int temp;
int state[<<];
int dp[][<<];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
int num;
scanf("%d",&num);
low[i]=low[i]|(num<<j);
}
}//处理每一行的状态
temp=;
for(int i=;i<(<<m);i++)
{
if((i&(i<<))==)
{
state[temp++]=i;
}
}//处理所有满足的状态
memset(dp,,sizeof dp);
for(int i=;i<temp;i++)
{
if((low[]&state[i])==state[i])
dp[][i]=; }//处理第一行 for(int i=;i<n;i++)
for(int j=;j<temp;j++)
{
if((low[i]&state[j])==state[j])
{
for(int k=;k<temp;k++)
{
if((state[j]&state[k])==)
dp[i][j]=(dp[i][j]+dp[i-][k])%mod;
}
}
}
int ans=;
for(int i=;i<temp;i++)
{
ans=ans+dp[n-][i];
ans=ans%mod;
}
cout<<ans<<endl;return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905