题目大意: 输入n,p:n个点,p条路 接下来n行输入c[]:在各个点需要花费的时间 接下来p行输入u,v,w:u点到v点的路需要花费时间w 求经过所有点且最后回到起点的最少花费时间 https://blog.csdn.net/HY_VFenux/article/details/68954199 将每条边的权值存为 路径花费*2+两端点花费 Kruscal求MST 最后加上开始位于起点的花费 即各个点中最少花费的一个 #include <bits/stdc++.h> #define INF 0…
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…
POJ 3253 Fence Repair STL堆操作 我想说,STL里堆是我目前见到最蛋疼的操作. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include <vector> #inc…
[题目链接] 点击打开链接 [算法] 状压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(…
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 ( 1 ≤ N ≤ 20,000 ) :将一块木板分为n块 每次切割木板的开销为这块木板的长度,即将长度为21的木板分为13和8,则开销为21 接下来n行描述每块木板要求的长度Li ( 1 ≤ Li ≤ 50,000 ) 木板长度恰好等于各段木板长之和 Sample Input 3858 Sample Output 34 挑战上的一个奇妙的贪心的方法 #include <bits/stdc++.h> #define ll long long using namespace…
题目大意: 输入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…