Ivan has n different boxes. The first of them contains some balls of n different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every i (1 ≤ i ≤ n) i-th box will contain all balls with co
有N堆石子,现要将石子有序的合并成一堆,规定如下:每次只能移动相邻的2堆石子合并,合并花费为新合成的一堆石子的数量.求将这N堆石子合并成一堆的总花费最小. 区间DP思想:现在小区间进行DP得到最优解,然后再利用小区间的最优解组合并求大区间的最优解.(需要从小到大枚举所有可能的区间) 代码(没提交过,不过应该正确): include using namespace std; const int maxn1=300; int main() { int n,a[maxn1]={0},sum[maxn1
题目网址:https://www.luogu.com.cn/problem/P1880 题意是:给定一个序列,最小规则是相邻两个值的合并,开销是他们的和,将整个序列合并成一个值的情况下,求解该值的最小值和最大值. 代码如下: #include<bits/stdc++.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; #define pf p
题:https://ac.nowcoder.com/acm/contest/4137/N 分析:注意题意,收益是a[i]*a[i+1],所以分析得,是∑∑a[i]*a[j] #include<bits/stdc++.h> using namespace std; typedef long long ll; ; int a[M]; int main(){ int n; cin>>n; ;i<=n;i++) cin>>a[i]; ll ans=; ;i<=n;i