最近题目都有状态压缩,我是蒟蒻,并不会状态压缩 然后我决定学了! 然后发现我学不来. OI-WIKI上的界面给我推荐了这道题https://oi-wiki.org/dp/state/ 状态压缩入门题,可惜我不会 下面是OIWIKI的代码 #include<bits/stdc++.h> using namespace std; int read(){//读入优化 ,w=;; ;ch=getchar();} )+(x<<)+ch-',ch=getchar(); return x*w;…
P1879 [USACO06NOV]玉米田Corn Fields 状压dp水题 看到$n,m<=12$,肯定是状压鸭 先筛去所有不合法状态,蓝后用可行的状态跑一次dp就ok了 #include<iostream> #include<cstdio> #include<cstring> #define re register using namespace std; const int p=1e9; ],f[][]; ][],len[]; int mod(int a)…
没学状压DP的看一下 合法布阵问题  P1879 [USACO06NOV]玉米田Corn Fields 题意:给出一个n行m列的草地(n,m<=12),1表示肥沃,0表示贫瘠,现在要把一些牛放在肥沃的草地上,但是要求所有牛不能相邻,问你有多少种放法. 分析:假如我们知道每行都有x种合法放法(也就是x种状态),所以对于第i行就有x种放法,那么对于第i+1行的每种放法就有对应的x种放法. 所以定义dp[i][j]表示第i行状态为j时的方法数(j=0,j<=x;j++),有转移方程:dp[i][j]…
P1879 [USACO06NOV]玉米田Corn Fields 题目描述 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…
洛谷P1879 [USACO06NOV]玉米田Corn Fields \(f[i][j]\) 表示前 \(i\) 行且第 \(i\) 行状态为 \(j\) 的方案总数.\(j\) 的大小为 \(0 \to (1 >> n - 1)\) . 第 \(i\) 行,种植状态为 \(j\) 的方案总数等于所有合法的 \(f[i-1][k]\) 之和. 状态 \(j\) 满足同一行内没有相邻的两块草地(没有共同边). 状态 \(j\) 和 \(k\) 满足相邻两行的种植情况没有两块草地有共同边. \[…
题目描述 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 b…
题目描述 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 b…
题目描述 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 b…
题目描述 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 b…
题目链接:https://www.luogu.org/problemnew/show/P1879 状压DP. 设dp[i][j]表示第i行,状态为j的方案数 初始dp[0][0] = 1 这样一共12行12列,最多1<<12. 这样转移时,只要满足上下没有两个1,这两行分别满足没有相邻1. 加法原理转移. \(j&k==0\) $ dp[i][j] += dp[i-1][k] $ #include <cstdio> #include <cstring> #inc…