poj3254 Corn Fields

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 34 ?

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.


第一道狀壓dp,看了別人的思路自己寫出來了.題目大意是給你一塊地,有能放牛的草地也有不能放牛的草地,而且兩頭牛不能同時安排在相鄰的草地上,問有多少種放法,草地長和寬都小于等于12。

這題的思路是這樣:先求出每一行的可以放的方案數,用num[i][j]記錄下來各個方案所對應的十進制數,用num1[i]記錄第i行的方案數,再初始化第一行dp[1][k]為1,然后使i從2到n循環,用dp[i][j]表示第i行第j種放置狀態下的總方案數,依次累加,動規方程為dp[i][j]=dp[i][j]+(num[i][j]&num[i-1][k])?0:dp[i-1][k].(k=1,2,...num1[i-1])。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
int num[15][5000],n,m,num1[15],dp[15][5000];
void hang(int i,int temp)
{int t=0,j;for(j=0;j<(1<<m);j++){if(j&(j<<1))continue;if(j&temp)continue;t++;num[i][t]=j;}num1[i]=t;
}int main()
{int i,j,c,temp,k,sum;while(scanf("%d%d",&n,&m)!=EOF){memset(num,0,sizeof(num));memset(num1,0,sizeof(num1));memset(dp,0,sizeof(dp));for(i=1;i<=n;i++){temp=0;for(j=1;j<=m;j++){scanf("%d",&c);c=1-c;temp=temp*2+c;}hang(i,temp);}for(j=1;j<=num1[1];j++){dp[1][j]=1;}for(i=2;i<=n;i++){for(j=1;j<=num1[i];j++){for(k=1;k<=num1[i-1];k++){if(num[i-1][k]&num[i][j])continue;dp[i][j]+=dp[i-1][k];}}}sum=0;for(j=1;j<=num1[n];j++){sum=(sum+dp[n][j])%100000000;}printf("%d\n",sum);}return 0;
}


轉載于:https://www.cnblogs.com/herumw/p/9464739.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/258706.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/258706.shtml
英文地址,請注明出處:http://en.pswp.cn/news/258706.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android獲取程序路徑 (/data/data/appname)

Android獲取文件夾路徑 /data/data/ http://www.2cto.com/kf/201301/186614.html String printTxtPath getApplicationContext().getPackageResourcePath() "/files/" fileName;> /data/app/com.example.fileoperation-2.apk/files/printMenu.txt String print…

javascript做極簡時鐘特效,再簡單沒思路你也做不出來

點擊查看時鐘特效極簡主義&#xff0c;程序員javascript打造極簡時鐘特效對于javascript特效的學習&#xff0c;重要的是邏輯思路&#xff0c;所以這個時鐘特效不是很華麗&#xff0c;但是功能都展現出來了&#xff0c;而學習javascript并不是單純的扣代碼&#xff0c;很多人都…

ubuntu中怎么打開python_如何在Linux Ubuntu 16.04下安裝及打開PyCharm

下載安裝 PyCharm下載好的文件的名稱可能是 ‘pycharm-community-2017.2.3.tar.gz’首先打開終端&#xff0c;然后通過下面的命令進入下載文件所在的文件夾&#xff1a;cd ~/Downloads或者如果文件夾是中文cd ~/下載然后&#xff0c;通過運行下面的命令找到你下載的文件的名字&…

圖像極坐標變換及在OCR中的應用

極坐標變換定義 我們知道在二維坐標系中&#xff0c;有直角坐標系&#xff0c;也有極坐標系&#xff0c;二者的轉換關系是&#xff1a; 如下圖&#xff1a; 如圖&#xff0c;直角坐標系的圓心與極坐標系的圓心一一對應&#xff0c;且圓弧BA可以通過極坐標變換到極坐標系ρr的…

Light OJ 1406 Assassin`s Creed 減少國家DP+支撐點甚至通縮+最小路徑覆蓋

標題來源&#xff1a;Light OJ 1406 Assassins Creed 意甲冠軍&#xff1a;向圖 派出最少的人經過全部的城市 而且每一個人不能走別人走過的地方 思路&#xff1a;最少的的人能夠走全然圖 明顯是最小路徑覆蓋問題 這里可能有環 所以要縮點 可是看例子又發現 一個強連通分量可能…

bootstrap-表單控件——單選按鈕水平排列

1.運行效果如圖所示2.實現代碼如下<!DOCTYPE html> <html> <head><meta charset"utf-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><title>表單控件——單選按鈕水平排列</title><!-- 最…

python中memoryerror_解決python報錯MemoryError

{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":4,"count":4}]},"card":[{"des":"阿里技術人對外發布原創技術內容的最大平臺&…

MongoDB使用小結:一些常用操作分享

MongoDB使用小結&#xff1a;一些常用操作分享 本文整理了一年多以來我常用的MongoDB操作&#xff0c;涉及mongo-shell、pymongo&#xff0c;既有運維層面也有應用層面&#xff0c;內容有淺有深&#xff0c;這也就是我從零到熟練的歷程。 MongoDB的使用之前也分享過一篇&#x…

【論文閱讀】Illuminating Pedestrians via Simultaneous Detection Segmentation

論文來源 ICCV2017arXiv reportgithub代碼(caffe-matlab) 本文的主要問題是行人檢測。作者探討了如何將語義分割應用在行人檢測上&#xff0c;提高檢測率&#xff0c;同時也不損壞檢測效率。作者提出了一種語義融合網絡&#xff08;segmentation infusion networks&#xff0…

跨域獲取json電商數據

url:http://www.darlingbank.com/cutpage/index.php/promote/edit/getfun/json/源碼&#xff1a; <ul class"cf" dataurl"http://www.paipai.com/sinclude/xml/tjw/tjw2014/tjw4/tjw179255804475.js" commlen"4" commsta"1" commtp…

Python ORM框架之 Peewee入門

之前在學Django時&#xff0c;發現它的模型層非常好用&#xff0c;把對數據庫的操作映射成對類、對象的操作&#xff0c;避免了我們直接寫在Web項目中SQL語句&#xff0c;當時想&#xff0c;如果這個模型層可以獨立出來使用就好了&#xff0c;那我們平臺操作數據庫也可以這么玩…

天聯高級版客戶端_金萬維天聯高級版服務器安裝配置全流程以及客戶端登錄流程...

今天下午&#xff0c;有一個使用千江軟件的用戶&#xff0c;他想實現千江軟件的異地訪問&#xff0c;經過他朋友也是金萬維天聯高級版的客戶的介紹&#xff0c;推薦我們幫他安裝天聯高級版&#xff0c;從而實現千江軟件的異地訪問&#xff0c;千江軟件本地訪問界面如下&#xf…

[C#]async和await刨根問底

上一篇隨筆留下了幾個問題沒能解決&#xff1a; 調用IAsyncStateMachine.MoveNext方法的線程何時發起的&#xff1f; lambda的執行為何先于MoveNext方法&#xff1f; 后執行的MoveNext方法做了些什么事情&#xff1f; 那么今天就來嘗試解決它們吧~PS: 本文中部分代碼來自上一篇…

模仿QQ截圖片

兩個picturebox,一個放圖片完整代碼如下using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using System.Xml; namespace T…

/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found錯誤的解決

轉載自&#xff1a;http://www.cnblogs.com/weinyzhou/p/4983306.html 升級cmake時&#xff0c;提示“Error when bootstrapping CMake:Problem while running initial CMake”&#xff0c;第二次運行./bootstrap時&#xff0c;直接的給出了錯誤原因&#xff1a; [rootloc…

Spring中Bean的定義繼承

以下內容引用自http://wiki.jikexueyuan.com/project/spring/bean-definition-inheritance.html&#xff1a; Bean定義繼承 bean定義可以包含很多的配置信息&#xff0c;包括構造函數的參數&#xff0c;屬性值&#xff0c;容器的具體信息例如初始化方法&#xff0c;靜態工廠方法…

python實時連接oracle_Python連接Oracle

Python連接Oracle當前環境&#xff1a;Linux Centos 71. 下載安裝包cx_Oracle由于我本地Python版本是2.7,所以選擇是2.7版本wget https://pypi.python.org/packages/e1/18/00987c6a9af9568ee87d1fcba877407684a3f1b87515e5eb82d5d5acb9ff/cx_Oracle-6.0rc1-py27-1.x86_64.rpm#m…

C語言字符串函數大全

轉載自http://www.360doc.com/content/08/0723/22/26860_1462024.shtml# C語言字符串函數大全 函數名: stpcpy 功能: 拷貝一個字符串到另一個 用法: char *stpcpy(char *destin, char *source); 程序例: #include<stdio.h> #include<string.h> int main(void) { ch…

Makefile中 -I -L -l區別

轉載自&#xff1a;http://blog.csdn.net/davion_zhang/article/details/41805641 我們用gcc編譯程序時&#xff0c;可能會用到“-I”&#xff08;大寫i&#xff09;&#xff0c;“-L”&#xff08;大寫l&#xff09;&#xff0c;“-l”&#xff08;小寫l&#xff09;等參數&am…

PLT redirection through shared object injection into a running process

PLT redirection through shared object injection into a running process