当前位置: 首页 > news >正文

POJ3254 Corn Fields

Corn Fields
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 14326 Accepted: 7509

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

 

状压DP

不能选相邻的格子。先预处理出所有可能的状态(其实没必要),枚举状态转移,累计方案数

 

 1 /*by SilverN*/
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 using namespace std;
 8 const int mod=1e8;
 9 int read(){
10     int x=0,f=1;char ch=getchar();
11     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
12     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
13     return x*f;
14 }
15 int m,n;
16 bool mp[13][13];
17 int f[13][1<<12];
18 int t[1<<12],cnt=0;
19 int ban[13];
20 void init(){
21     int ed=(1<<n)-1;
22     for(int i=0;i<ed;i++){
23         int j,tmp=1;
24         for(j=0;j<n-1;j++){
25             if((i&tmp) && (i&(tmp<<1)))break;
26             tmp<<=1;
27         }
28         if(j!=n-1)continue;
29         t[++cnt]=i;
30     }
31     return;
32 }
33 int main(){
34     int i,j;
35     m=read();n=read();
36     for(i=1;i<=m;i++){
37         for(j=0;j<n;j++){
38             mp[i][j]=read();
39             if(!mp[i][j])ban[i]|=(1<<j);
40         }
41     }
42     init();
43 //    for(i=1;i<=cnt;i++)printf("%d ",t[i]);printf("\n");
44     f[0][1]=1;
45     int ed=(1<<n)-1;
46     for(i=1;i<=m;i++){
47         for(int p=1;p<=cnt;p++){
48             if(t[p]&ban[i-1])continue;
49             for(int r=1;r<=cnt;r++){
50                 if(t[r]&ban[i])continue;
51                 if(t[p]&t[r])continue;
52                 f[i][r]=(f[i][r]+f[i-1][p])%mod;
53             }
54         }
55     }
56     int ans=0;
57     for(i=1;i<=cnt;i++){
58         ans=(ans+f[m][i])%mod;
59     }
60     printf("%d\n",ans);
61     return 0;
62 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/6437945.html

相关文章:

  • CSS颜色大全
  • Elasticsearch之IKAnalyzer的过滤停止词
  • ubuntu 14.04 安装jdk 1.8
  • 提升用户体验的利器——使用Vue-Occupy实现占位效果
  • js 获取图片url的Blob值并预览
  • thinkphp5在URL地址里隐藏模块名
  • Rancher v1.2:网络架构解读
  • mongodb 数组操作
  • linux的运维管理UNIT4
  • 细说firewalld和iptables
  • Linux基础知识(2)
  • 2016-2017-2点集拓扑作业拾遗
  • Google安全视频
  • webpack笔记1
  • httpclient就是个能发送http连接的工具包,包括能发送post请求和get请求
  • [译]CSS 居中(Center)方法大合集
  • 《Java编程思想》读书笔记-对象导论
  • angular2 简述
  • Computed property XXX was assigned to but it has no setter
  • CSS 提示工具(Tooltip)
  • eclipse(luna)创建web工程
  • egg(89)--egg之redis的发布和订阅
  • HTML中设置input等文本框为不可操作
  • JavaScript 是如何工作的:WebRTC 和对等网络的机制!
  • JavaScript对象详解
  • mongo索引构建
  • PyCharm搭建GO开发环境(GO语言学习第1课)
  • Spring思维导图,让Spring不再难懂(mvc篇)
  • 彻底搞懂浏览器Event-loop
  • 从tcpdump抓包看TCP/IP协议
  • 基于Vue2全家桶的移动端AppDEMO实现
  • 盘点那些不知名却常用的 Git 操作
  • 思否第一天
  • 鱼骨图 - 如何绘制?
  • 运行时添加log4j2的appender
  • 智能合约Solidity教程-事件和日志(一)
  • Play Store发现SimBad恶意软件,1.5亿Android用户成受害者 ...
  • 我们雇佣了一只大猴子...
  • #我与Java虚拟机的故事#连载16:打开Java世界大门的钥匙
  • (12)Hive调优——count distinct去重优化
  • (javascript)再说document.body.scrollTop的使用问题
  • (Oracle)SQL优化技巧(一):分页查询
  • (二)【Jmeter】专栏实战项目靶场drupal部署
  • (理论篇)httpmoudle和httphandler一览
  • (每日持续更新)jdk api之StringBufferInputStream基础、应用、实战
  • (七)微服务分布式云架构spring cloud - common-service 项目构建过程
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • (四)Tiki-taka算法(TTA)求解无人机三维路径规划研究(MATLAB)
  • (提供数据集下载)基于大语言模型LangChain与ChatGLM3-6B本地知识库调优:数据集优化、参数调整、Prompt提示词优化实战
  • .apk文件,IIS不支持下载解决
  • .net Application的目录
  • .Net FrameWork总结
  • .Net 代码性能 - (1)
  • .NET/C# 项目如何优雅地设置条件编译符号?