摘要: http://poj.org/problem?id=1273基本最大流问题 基本介绍http://www.cnblogs.com/north_dragon/archive/2010/05/23/1741951.html通俗证明http://blog.csdn.net/kdqzzxxcc/article/details/7881169#include <iostream>#include <cstdio>#include <cstring>#include <queue>using std::queue;const int maxn = 205, 阅读全文
posted @ 2013-03-04 17:07 April_Tsui 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 最长公共子序列 变形重点是最后不是求长度 而是最长序列的列举其中一种情况所以注意标记 刚开始用dp[i][j] = 1,2,3,4…… 就以为是解 其实不然很难具体说 看代码吧View Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using std::string;const int maxn = 105;char a[maxn][35], b[maxn][35];int dp[maxn][maxn];char ans[maxn][m 阅读全文
posted @ 2013-03-04 13:23 April_Tsui 阅读(144) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1159时间复杂度n2算法(n<5000) 814MS 212K 供参考求出逆序列的最长公共子序列长度 再用len减他即可因为n=5000, 若dp [n][n] 超内存, 听说可以改成short 水过也可以使用滚动数组 具体看代码View Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>const int maxn = 5005;char a[maxn], b[maxn];int 阅读全文
posted @ 2013-03-03 20:20 April_Tsui 阅读(157) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1458经典dp 将数组从下标1开始 可以不用特殊处理第一个数据strlen(a+1) 而不是 strlen(a)scanf 以 %s 形式 自动忽略空格 回车输入缓冲View Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>const int maxn = 1000;char a[maxn], b[maxn];int dp[maxn][maxn];int max(int a, int 阅读全文
posted @ 2013-03-03 19:17 April_Tsui 阅读(149) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1659Havel 定理 贪心。。考虑要全面#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>using std::sort;struct Node{ int pos, w; bool operator < (Node a) { return w >= a.w ; }}lake[25];int map[25][25];int main(){ int cas, i, j, n, a; boo 阅读全文
posted @ 2013-02-28 09:59 April_Tsui 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Link:http://poj.org/problem?id=2553求缩点后出度为0的点。。。 tarjan again。。。首次用了memcpy方法 感觉不错!注意init()要在输入了 m n之后调用,一般来说上轮case里数组是 a[i] ++形式的 要再次赋初值而有变量cnt控制数组大小的数组 不必赋值 只要控制cnt=0 就可以了如for(int i=1; i<=cnt; i++) a[i]=xxxx; 这类View Code #include <cstdio>#include <iostream>#include <stack>#incl 阅读全文
posted @ 2013-02-27 16:40 April_Tsui 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Link:http://poj.org/problem?id=2186注意题中 是considered popular by every other cow 意思是除了他自己其他牛都喜欢他的我一开始理解为 the most popular =-=利用tarjan算出强连通分支 缩点 得出出度为0的个数num(num一定不会等于0的)如果num为1 则为该强连通图的牛个数否则 没有这样的牛NOTE: 题中说明是稀疏图 最好用邻接表View Code #include <cstdio>#include <iostream>#include <stack>usin 阅读全文
posted @ 2013-02-27 14:42 April_Tsui 阅读(135) 评论(0) 推荐(0) 编辑
摘要: Link:http://poj.org/problem?id=1236/******** HOW TO SOLVE *******利用tarjan算出强连通图的集合,把一个强连通图看做一个节点,算出每个节点之间的路径(即强连通图之间的路径) 设入度为0的点个数为fromNum,出度为0的点个数为outNum答案即 fromNum 和 max(outNum, fromNum)注意只有一个强连通图的特殊情况!!******** HOW TO SOLVE ********//******* TO PROVE ********<1>弱连通的有向图如果没有出度或入度为0的节点则它必强连通 = 阅读全文
posted @ 2013-02-27 11:31 April_Tsui 阅读(186) 评论(0) 推荐(0) 编辑
摘要: http://code.google.com/codejam/contest/1460488/dashboard#s=p2我做模拟题是一向不行的 这道题搞了我m久 发现我对数字真的是非常不敏感~只是解决了small data而已 large data模拟肯定是不行的这道题 有一个点我觉得很巧妙而且终于将sprintf sscanf strncpy 用了一下 挺好用哒~#include <cstdio>#include <algorithm>#include <cmath>using namespace std;#define MAX 2000000int v 阅读全文
posted @ 2013-01-07 16:05 April_Tsui 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 对于if else if我一直分得非常不清楚 在这上面错了很多次写下今天的一点小感想。#include <stdio.h>int main(){ int a, b ; int m ; scanf("%d %d %d", &a, &b, &m); if( a == 1 && m == 1 ) printf("a=%d\n", a); else if( b == 1 ) printf("a=%d b=%d", a, b); else if(b==2) printf("a=%d 阅读全文
posted @ 2013-01-07 13:42 April_Tsui 阅读(188) 评论(0) 推荐(0) 编辑