算法
鹭别江
这个作者很懒,什么都没留下…
展开
-
HDU 3342
这题没什么还说的,拓扑排序判断回路模板。#include #include #include using namespace std;bool judge(int v[105][105], int d[105], int n){ for(int i = 0; i < n; i++){ int tmp = n; for(int j = 0原创 2015-02-05 20:34:26 · 269 阅读 · 0 评论 -
HOJ2544
最长上升子序列(LIS)的nlogn算法。用dp[i]来表示长度为i的LIS末尾数字的最小值。每输入一个数,就把它插到dp数组合适的位置,而dp[]一定是有序的(因为每一步更新的保证),因此可以二分,用logn的复杂度就可以完成插入(准确地说是更新)。这个链接里讲得比较清楚:http://www.felix021.com/blog/read.php?1587#include原创 2015-02-22 21:25:27 · 369 阅读 · 0 评论 -
Codeforces 510C
拓扑排序模板题,本身没什么好说的,但是刘汝佳在白书中用到一个技巧,就是一个数组可以表示结点的三种状态:0代表未被访问过,1代表已经访问过,-1代表正在访问。#include #include using namespace std;int c[30], gra[30][30];int topo[30], cnt;int dfs(int u){ c[u] = -1;原创 2015-02-11 17:02:14 · 424 阅读 · 0 评论 -
HDU 2955, 3496 兼作01背包总结
HDU 2955这道题如果把被抓概率当作背包容量,将会十分麻烦,因为概率不一定是2位小数,放大后空间和时间上都过不去。这时候需要转化,我们可以求盗取i单位钱不被抓获的的可能性最大值,容量变为盗取的钱数,问题就好解决了。#include #include #include using namespace std;int main(){ int t; scanf("原创 2015-02-15 22:04:52 · 386 阅读 · 0 评论 -
HOJ1215 HDU1203
两道题都是01背包的入门题。共同点:求放入背包物品的最小值。区别:前者的容量有下限(这和一般的背包相反)。有一个tip:使用memset函数要注意,它并不是简单的初始化,慎用。HOJ1215转化为求”使得血量达到100所消耗分数的最小值“#include #include #include using namespace std;const int INF = 0x原创 2015-02-13 22:21:39 · 323 阅读 · 0 评论