https://www.luogu.org/problem/show?pid=2212 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with…
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 &…
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 &…
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 &…
传送门 题解:计算欧几里得距离,Krusal加入边权大于等于c的边,统计最后树的边权和. 代码: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 2009 using namespace std; int n,c,cnt,tot,ans; int xi[maxn],yi[maxn],fa[maxn]; struct Edge{ int…
题目链接: https://www.luogu.org/problemnew/show/P2212 思路: 一道最小生成树裸题(最近居然变得这么水了),但是因为我太蒻,搞了好久,不过借此加深了对最小生成树的认识. 首先这明显是个稠密图,有\(\sum_{n-1}^{i=1}i=n*(n-1)/2\)条边,看起来\(Prim\)会明显优于\(Kruskal\),于是这道题我用了三种方法 \(Kruskal\) 简单易懂,简洁优美 耗时/内存 344ms, 24343KB 代码: #include…
题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system tosend water between his N fields (1 <= N <= 2000).Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 <= xi, yi <= 1000. The cost of buildi…
洛谷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\) 满足相邻两行的种植情况没有两块草地有共同边. \[…
一道状压\(DP\) POJ原题链接 洛谷原题链接 很显然的状压,\(1\)表示种植,\(0\)表示荒废. 将输入直接进行状压,而要满足分配的草场是适合种草的土地,即是分配时的状态中的\(1\),在输入对应的状态中也是\(1\),而\(0\)对应\(0,1\)都可以. 设输入的这行状态为\(a[i]\),分配时的这行状态为\(x\),则用位运算来表示上述条件即\((\sim a[i])\&x=0\),设其为函数\(judge(i,x)\). 因为每个草场不能相邻,对于每一行,可以先预处理出在二进…
洛谷P1879:https://www.luogu.org/problemnew/show/P1879 思路 把题目翻译成人话 在n*m的棋盘 每个格子不是0就是1 1表示可以种 0表示不能种 相邻的格子不能同时种 求总方案数 把每行看成一个n位的2进制数 预处理出每行的状态后 进行DP即可 PS:在处理每行的初始状态时 将其取反后更好操作 代码 #include<iostream> #include<cstdio> using namespace std; #define mod…