摘要: 刘汝佳说这是一道最短路,可是我怎么也想不出如何建图,把问题转换为最短路问题,我就想自己的办法。感觉这个题可以用三维dp;每一维代表一个瓶子 f[maxn][maxn][maxn];状态转移我就想:每一次倒水一定要把一个倒完或把另一个装满才有意义,因为只有这样三个瓶的水量才知道;所以可以根据这个进行状态转移。状态转移代码有点啰嗦,主要是不同维不能统一一个式子。最后想到用队列来存变化的状态。 1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 #include <iostream& 阅读全文
posted @ 2013-05-25 19:16 等待最好的两个人 阅读(305) 评论(0) 推荐(0) 编辑
摘要: 由于是背包问题,但直接用dp, 不满足dp中的无后效性,所以用排序来改变顺序;#include <cstdio>#include <cmath>#include <algorithm>#include <iostream>#include <queue>#include <cstdlib>#include <cstring>#define maxn 3005using namespace std;const int INF = 0x3f3f3f;int dp[10005];int ans = 0;struct 阅读全文
posted @ 2013-05-25 10:17 等待最好的两个人 阅读(170) 评论(0) 推荐(0) 编辑