摘要:
题意:给定 n 个结点的树,结点带权,给定一个数 k,要求把这棵树分成 k 个部分,使得每部分的结点权值和中的最大值最小,求该最小值。 解法:要使得最大值最小,所以需要二分枚举最大值lim,问题变成判断是否能划分出k-1个连通块使得最大值不超过lim,即判定划分连通块权值不超过lim的个数是否小于等 阅读全文
摘要:
与01背包结合的: #include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; int dp[maxn][maxn]; int main(){ int n,V,M;cin>>n>>V>>M; for(int i=1;i<=n; 阅读全文
摘要:
不优化朴素解法,01背包看出S=1,完全背包看成S=INF,再跑多重背包(时间复杂度高,3层for循环): #include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; int dp[maxn]; int v[maxn],w[m 阅读全文
摘要:
朴素版本: #include<bits/stdc++.h> using namespace std; const int maxn=1005; int dp[maxn][maxn]; int v[maxn][maxn],w[maxn][maxn],s[maxn]; int main(){ int n 阅读全文
摘要:
朴素无优化版本: #include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; int dp[maxn][maxn]; int v[maxn],w[maxn],s[maxn]; int main(){ int n,m;scanf 阅读全文
摘要:
暴力朴素无优化写法(3维for+2维数组): #include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; int dp[maxn][maxn]; int v[maxn],w[maxn]; int main(){ int n,m 阅读全文
摘要:
朴素2维无优化写法: #include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; int dp[maxn][maxn],v[maxn],w[maxn]; int main(){ int n,m;scanf("%d%d",&n, 阅读全文