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…
题目链接 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相邻.问有多少种放牛方案(一头牛都不放也是一种方案) 分析:每一行看做一个状态,用一个二进制数来表示,每一行会排出牛和牛相邻的情况:由上一行转移到下一行的条件就是这一行和上一行不会存在1在同一列,也就是与操作后为0, 状态表示: dp[state][i] 表示 在状态为state情况下第i行可以满足的方案数 状态转移:DP[s…
问题: Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangle…
题目:http://poj.org/problem?id=3254 1.枚举行: 2.把有影响的“放不放牛”加入参数中,用二进制数表示该位置放不放牛,再用十进制数表示二进制数: 3.优美的预处理list: 4.优美的位运算比较二进制. #include<iostream> #include<cstdio> #include<cstring> using namespace std; ],cnt,a[],d[][],ans; ; ]; /*计算有多少种合法者 :1431…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 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 yumm…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 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 yumm…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5763   Accepted: 3052 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 yumm…
题目大意 给定一个N*M大小的土地,土地有肥沃和贫瘠之分(每个单位土地用0,1来表示贫瘠和肥沃),要求你在肥沃的单位土地上种玉米,如果在某个单位土地上种了玉米,那么与它相邻的四个单位土地是不允许种玉米的,问你有多少种种玉米方案.(不种一算一种方案) 题解 很基础的状态压缩DP,我们可以逐行的进行状态转移,用二进制来表示一行的状态,方程表示为:dp[i]j]+=dp[i-1][k],表明我们可以从上一行的状态k转移到当前行的状态j,那怎么样的k才是符合情况的呢?只需要j&k==0即可,也就是玉米不…
题意:在由方格组成的矩形里面种草,相邻方格不能都种草,有障碍的地方不能种草,问有多少种种草方案(不种也算一种方案). 分析:方格边长范围只有12,用状态压缩dp好解决. 预处理:每一行的障碍用一个状态保存好     每一行不考虑障碍的所有符合要求的状态保存好     第一行的方案数记录好. 然后一行一行递推,每一行只与上一行有关. #include <iostream> #include <algorithm> #include <cmath> #include <…
下面有别人的题解报告,并且不止这一个状态压缩题的哦···· http://blog.csdn.net/accry/article/details/6607703 下面是我的代码,代码很挫,绝对有很大的优化的空间···· #include <cstdio> #include <cstring> ][( << ) + ]; //检查一行的奶牛放置情形是否合理 //即是否有相邻的两个1,没有返回true bool checkHori(int state) { )) ) ret…