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…
Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 200000 + 4; int lazy[maxn << 2], sumv[maxn << 2]; inline void pushdown(int o, int l,int r) { int ls = (o << 1), rs = (o…
题目大意: 输入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…
Link: USACO 2017 Dec Gold 传送门 A: 为了保证复杂度明显是从终结点往回退 结果一开始全在想优化建边$dfs$……其实可以不用建边直接$multiset$找可行边跑$bfs$就行了 由于保证每个点只进队列一次.被搜索到一次,因此复杂度为$O(n*log(n))$ #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typ…