随笔分类 - 动态规划
摘要:"P1474 货币系统 Money Systems" !! 不是noip2018的那道题。 简单的多重背包的变式。 cpp include include using namespace std; //Mystery_Sky // define ll long long define M 10000
阅读全文
摘要:"庆功会" 多重背包模板 比01背包多了一个将某种物品拆分的过程。
阅读全文
摘要:"公共子序列" 多组输入的 "最长公共子序列" 。 cpp include include include include using namespace std; //Mystery_Sky // define M 1000 string s1, s2; int f[M][M], len1, le
阅读全文
摘要:"方格取数" cpp include include using namespace std; //Mystery_Sky // define M 11 int f[M][M][M][M], a[M][M]; int n, x, y, z; int max1, max2; int main() {
阅读全文
摘要:"装箱问题" 01背包的变式,费用=价值。
阅读全文
摘要:"完全背包问题" 完全背包模板题 cpp include include using namespace std; //Mystery_Sky //完全背包模板 define M 1010 int f[M], c[M], w[M]; int v, m, ans; int main() { scanf
阅读全文
摘要:"01背包问题" 经典的01背包问题模板 这里提供两种做法:
阅读全文
摘要:"最长公共子序列" cpp include include include using namespace std; //Mystery_Sky // define M 1000 string s1, s2; int len1, len2; int f[M][M], ans; int main()
阅读全文
摘要:"最大子矩阵" 无脑操作题,由于n include using namespace std; //Mystery_Sky // define M 1000 int f[M][M], a[M][M]; int n, ans, maxn; int main() { scanf("%d", &n); fo
阅读全文
摘要:"最大上升子序列和" "最长上升子序列" 的变式。 状态转移方程: if(ai aj) fi = max(fi, fj+ai) cpp include include using namespace std; //Mystery_Sky // define M 1010 int maxn, n; i
阅读全文
摘要:"摘花生" 思路与 "最低通行费" 相似 cpp include include include include using namespace std; //Mystery_Sky // define M 1010 int a[M][M], f[M][M]; int t, n, m; int ma
阅读全文
摘要:"登山" 与 "合唱队形" 只差输出方式,难度较低。
阅读全文
摘要:"合唱队形" 对于每个点,找到以这个点为终点的最长上升序列长度以及以这个点为起点的最长下降序列长度,找到二者之和最大的点,然后用总人数减去该点二者之和即可。
阅读全文
摘要:"最低通行费" 由题意可得:第一行所有点只能一直左走走到,所以f[i][j] = a[i][j] + f[i][j 1], 同理第一列的点也只能一直向下走走到,f[i][j] = a[i][j] + f[i 1][j] 。 预处理完后,余下所有点到达该点的最小费用都等于min(到左边的点的最小费用,
阅读全文
摘要:"最长上升子序列" cpp include include using namespace std; //Mystery_Sky //最长上升子序列 define M 1010 int f[M], a[M], n; int ans; int main() { scanf("%d", &n); for
阅读全文
摘要:"拦截导弹(Noip1999)" 经典dp题目,这个做法并非最优解,详细参考洛谷 "导弹拦截" ,想想200分的做法。 cpp include include using namespace std; //Mystery_Sky //最长不上升序列+最长不下降序列 define M 1010 int
阅读全文
摘要:"三角形最佳路径问题" cpp include include using namespace std; //Mystery_Sky //还是 数字金字塔 define M 200 int f[M][M], a[M][M]; int ans, n; int main() { scanf("%d",
阅读全文
摘要:"求最长不下降序列" 状态转移方程:if(ai aj) fi = max(fi, fj+1)
阅读全文
摘要:"数字金字塔" 万年dp入门题 cpp include include include using namespace std; //Mystery_Sky // define M 1010 int f[M][M], a[M][M]; int n, ans; int main() { scanf("
阅读全文