摘要: 注意:当杯子为圆柱时也要二分,不能直接算。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring>11 #include <algorithm>12 #include <string>13 #include & 阅读全文
posted @ 2013-02-20 20:27 發_ 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 因为 0 ≤ Vi , Ci ≤ 10 , 范围很小,故可以转化为多重背包+二进制优化来解决。分解为系数为1,2,4,8...Mi-2^k+1的物品再做01背包。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring>11 #incl 阅读全文
posted @ 2013-02-19 17:36 發_ 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 题意:有n个品牌,每个品牌至少买一件。01背包加上一维,设计状态dp[k][i]表示前k种花费i所取得的最大值,状态可由前k-1种和当前品牌取得,注意初始化和方程的位置(无后效性)。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring&g 阅读全文
posted @ 2013-02-19 13:13 發_ 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 二维费用背包问题有两个限制条件:电影时长和看电影的部数。需要注意一下初始化dp[i][0] = 0,其余未知,因为看电影是一部一部来,所以当前dp值只能衔接前一部的dp值。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring>11 阅读全文
posted @ 2013-02-18 20:40 發_ 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 分组背包一水~View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring>11 #include <algorithm>12 #include <string>13 #include <utility> 阅读全文
posted @ 2013-02-18 19:34 發_ 阅读(138) 评论(0) 推荐(0) 编辑
摘要: ans = (m+n)!*(m-n+1)/(m+1).大数乘小数,大数除小数。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring>11 #include <algorithm>12 #include <strin 阅读全文
posted @ 2012-12-11 18:25 發_ 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 题意:判断最小生成树是否唯一。分析:只需要判断最小生成树与次小生成树的总权值是否相等。判断次小生成树的方法:kruskal O(n^3):先求一次最小生成树,然后枚举去掉生成树中的边,再求n-1次最小生成树,去最小的一棵。prim O(n^2):先求一次最小生成树,记录树上的边,并且保存每个环中的最大边,然后用一次DP枚举掉树上的边,更新生成树的权和,取最小值。kruskal 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include < 阅读全文
posted @ 2012-12-09 17:08 發_ 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 卡特兰数高精度。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring>11 #include <algorithm>12 #include <string>13 #include <utility> 阅读全文
posted @ 2012-11-28 19:42 發_ 阅读(219) 评论(0) 推荐(0) 编辑
摘要: poj这题数据很水很容易过,然而hdu的这题可能是因为case太多O(125*125*n)的复杂度TLE,最后用了快速幂的方法优化到O(125*125*logn)过了。140MS。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath> 10 #include <cstring&g 阅读全文
posted @ 2012-11-28 14:02 發_ 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 题意:有n个垃圾,机器人要按照编号从小到大捡但手中的垃圾不得超过C,求出机器人行走的最短总路程。做法:设dp[i]为捡第i个垃圾的最短距离,dist[i]为按顺序的总长,dis_ori[i]为i到原点的距离。不难得出:dp[i] = min{dp[j] + dis_ori[j+1] + distance[j+1,i] + dis_ori[i] } ; w(j+1,i)<=C = min{dp[j] + dis_ori[j+1] - dist[j+1]} + dist[i] + dis_ori[i] ; w(j+1,i)<=C用单调队列可以解决min的值,复杂度O(n... 阅读全文
posted @ 2012-11-18 11:16 發_ 阅读(335) 评论(0) 推荐(0) 编辑