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…
题目大意: 输入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…
Link: USACO 2018 Feb Gold 传送门 A: $dp[i][j][k]$表示前$i$个中有$j$个0且末位为$k$的最优解 状态数$O(n^3)$ #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int,int> P; ,INF=<<; int n,dat[MAXN],dp…
Link: USACO 2018 Jan Gold 传送门 A: 对于不同的$k$,发现限制就是小于$k$的边不能走 那么此时的答案就是由大于等于$k$的边形成的图中$v$所在的连通块除去$v$的大小 为了优化建图过程,考虑离线,将询问和边都按权值从大到小排序,依次加边即可 维护连通性和连通块大小用并查集 #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long lon…