题目大意: 输入n m 接下来n行m列 0表示不能种玉米 1表示能 要求种玉米位置的上下左右四连通区域不能种玉米 输出方案数 Sample Input 2 31 1 10 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 square…
USACO 2006 November Gold Corn Fields 题目描述: Farmer John has purchased a lush new rectangular pasture composed of M by N square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertil…
[题目链接] 点击打开链接 [算法] 状压DP [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 12 #define MOD 100000000 int M,N,i,j,k,ans,state; ][(<<)+],f[MAXN+][(<<)+],cnt[MAXN+],mat[MAXN+][MAXN+]; template <typename T> inline void read(…
!!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostream> #include <cstdio> #include <cstring> #define N 13 #define M 1<<13 #define MOD 1000000000 using namespace std; int n,m,t,ans; int s…
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 plan…
描述 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…
题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K 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…
题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表示.第i行的状态只与上一行有关. 此blog讲的很清楚:传送门 //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #in…
POJ 3253 Fence Repair STL堆操作 我想说,STL里堆是我目前见到最蛋疼的操作. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include <vector> #inc…
题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题的特点就是只有两种状态 所以用0 1表示两种状态 用位运算判断是否符合条件 然后将前一行的合理状态转移到后一行 最后统计最后一行的状态 dp[i][j]代表第i行以第j种状态放牛时有多少种不同的状态 (c++的语言特性是 封装 继承 多态~) /* *************************…