洛谷3004 [USACO10DEC]宝箱Treasure Chest】的更多相关文章

题目:https://www.luogu.org/problemnew/show/P3004 一眼看上去就是记忆化搜索的dp.像 一双木棋 一样. 结果忘了记忆化.T了5个点. 然后加上记忆化.MLE. 参考一些,改成循环的dp.还是MLE.哈哈,根本没改数组大小嘛! 又参考一些. 分析转移,发现它可以设计成滚动数组. 总之就是这样一道明明是简单题的题.自己还是需要多练习…… #include<iostream> #include<cstdio> #include<cstri…
P3004 [USACO10DEC]宝箱Treasure Chest 题目描述 Bessie and Bonnie have found a treasure chest full of marvelous gold coins! Being cows, though, they can't just walk into a store and buy stuff, so instead they decide to have some fun with the coins. The N (1…
P3004 [USACO10DEC]宝箱Treasure Chest 题目描述 Bessie and Bonnie have found a treasure chest full of marvelous gold coins! Being cows, though, they can't just walk into a store and buy stuff, so instead they decide to have some fun with the coins. The N (1…
区间DP,但是卡空间. n2的就是f[i,j]=sum[i,j]-min(f[i+1][j],f[i][j-1])表示这个区间和减去对手取走的最多的. 但是空间是64MB,就很难受 发现一定是由大区间转移到小区间,区间长度差为1 式子变成 :f[i,i+len]=sum[i,i+len]-min(f[i+1,i+len],f[i,i+len-1])然后就枚举len,就可以求出结果. #include <iostream> #include <cstdio> #include <…
第一眼:区间DP,可以瞎搞 f[i][j]=max(sum(i,j)-f[i+1][j],sum(i,j)-f[i][j-1]) 提出来就是f[i][j]=sum(i,j)-min(f[i+1][j],f[i][j-1]) 可是空间是64M,就很难受,第二个数据点是极限数据 尝试了用部分记忆化的方式找空间时间平衡,但是这样显然是不对的,看起来“省下的空间”实际上成为了更多的栈空间.. 考虑写一维的DP,既然不可能消一维,就把另一维藏起来. f[i]表示原来的f[i][i+len],外层依旧枚举l…
洛谷 P3003 [USACO10DEC]苹果交货Apple Delivery 题目描述 Bessie has two crisp red apples to deliver to two of her friends in the herd. Of course, she travels the C (1 <= C <= 200,000) cowpaths which are arranged as the usual graph which connects P (1 <= P &l…
题目:https://www.luogu.org/problemnew/show/P3004 似乎有点博弈的意思,但其实是DP: f[i][j] 表示 i~j 的最优结果,就可以进行转移: 注意两个循环的顺序,要先算出 i+1 ,但要用之前的 j-1 ,所以一个倒序一个正序. 代码如下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; ][],s[]; int main…
P3003 [USACO10DEC]苹果交货Apple Delivery 题目描述 Bessie has two crisp red apples to deliver to two of her friends in the herd. Of course, she travels the C (1 <= C <= 200,000) cowpaths which are arranged as the usual graph which connects P (1 <= P <=…
P3003 [USACO10DEC]苹果交货Apple Delivery 这题没什么可说的,跑两遍单源最短路就好了 $Spfa$过不了,要使用堆优化的$dijkstra$ 细节:1.必须使用优先队列+堆 2.更新方式跟$Spfa$有所不同 #include<bits/stdc++.h> using namespace std; void in(int &x){ register ;; ;c=getchar();} +c-';c=getchar();} x*=f; } ],vis[],d…
G - Zombie’s Treasure Chest Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description   Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest,…